English 中文(简体)
c c#/.netx.x是否采用了双重联系的清单(可在后向后转)?
原标题:Does c#/.net x.x have an implementation of a doubly linked list (that can be iterated over backwards)?

我一直在寻找在c#中实现双重联系名单的标准(因此,我有一份链接的清单,我可以战胜落后),不能找到一个。 我认为,像这样简单的事情,必须有一个我刚刚失踪的执行。

如果确实存在,则存在哪一个版本的c#/.net?

反常似乎并不是在c#中做的。 我的思想是否在++/stl模式中 st过太多,或者在c#中如此缺乏?

我知道有联系的List,但是,由于未能找到一种办法,使之摆脱后退,我假定这种联系是紧密相连的。

如果挂钩的List是双倍地联系在一起的,那么,如何扭转这种倒退(有效)?

最佳回答

以及在此所作的答复,你可以写上一条延伸方法,以LinkedList<T>,使之稍为容易再利用:

public static IEnumerable<T> Backwards<T>(this LinkedList<T> list)
{
    LinkedListNode<T> node= list.Last;
    while (node != null)
    {
        yield return node.Value;
        node = node.Previous;
    }
}

使用:

foreach (string x in list.Backwards())
{
    // ...
}
问题回答

反之,以下法典将有效地使一名联系人卷入:

        LinkedList<string> list = new LinkedList<string>
            (new[] {"cat", "dog", "frog", "antelope", "gazelle"});
        LinkedListNode<string> item = list.Last;
        do
        {
            Console.WriteLine(item.Value);
            item = item.Previous;
        }
        while (item != null);
        Console.ReadKey();

这里的关键是,一名联系人只提到名单上的第一和最后一例联系人。 Each Linked 证人名单提到名单上的下一个和前一个项目(或名单的每个末尾都是无效的),也提到价值财产。 这意味着从第一份或最后一份《联系文件》中分离出来是容易的,但随机接触要求从名单上的第一份或最后一份清单中分离出来。

如果你需要照样插入,则使用联系语言。 添加新的联系语言。

How about System.Collections.Generic.LinkedList()

这里是关于MSDN的文献:

http://msdn.microsoft.com/en-us/library/he2s3bh7.aspx

Version Info
.NET Framework: Supported in: 3.5, 3.0, 2.0
.NET Compact Framework: Supported in: 3.5, 2.0
XNA Framework: Supported in: 3.0, 2.0, 1.0

尽管如此,我同其他人一样认为,在开展这种丰富框架的工作时,通常更愿意使用一种更高的抽象性。

How about LinkedList?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签