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()));
}
}