C# 泛型链表

发布于 2016-10-18  190 次阅读


       internal class Node
        {
            protected Node m_next;
            public Node(Node next)
            {
                m_next = next;
            }
        }
        internal sealed class TypeNode<T> : Node
        {
            public T m_data;
            public TypeNode(T data) : this(data, null)
            {
            }
            public TypeNode(T data, Node next) : base(next)
            {
                m_data = data;
            }
            public override string ToString()
            {
                return m_data.ToString() + ((m_next != null) ? m_next.ToString() : string.Empty);
            }
        }
        private static void DifferentDataLinkedList()
        {
            Node head = new TypeNode('.');
            head = new TypeNode(DateTime.Now, head);
            head = new TypeNode("Today is ", head);
            Console.WriteLine(head.ToString());
        }

LoneKing