如何使用泛型链表

2016-06-11  本文已影响0人  目标肢解

LinkedList是泛型链表,也是用节点存取,节点类型为LinkedListNode<T> ,与ListDictionary的节点不同的是,LinkedListNode<T>有next和prev两个指向,说明LinkedList是双向链表,而ListDictionary是单向链表


class Program

{

static void Main(string[] args)

{

Node head = new TypedNode('.');

head = new TypedNode(DateTime.Now, head);

head = new TypedNode(" Today is ", head);

Console.WriteLine(head.ToString());

Console.ReadLine();

}

}

internal class Node

{

protected Node m_next;

public Node(Node next)

{

m_next = next;

}

}

internal class TypedNode : Node

{

public T m_data;

public TypedNode(T data)

: this(data, null)

{

}

public TypedNode(T data, Node next)

: base(next)

{

m_data = data;

}

public override string ToString()

{

return m_data.ToString() + ((m_next == null ? null : m_next.ToString()));

}

}

上一篇下一篇

猜你喜欢

热点阅读