汎用チェーンテーブル

4107 ワード


 
 1     internal class Node

 2     {

 3         protected Node m_next;

 4         public Node(Node next)

 5         {

 6             m_next = next;

 7         }

 8 

 9     }

10     internal class TypedNode<T> : Node

11     {

12         public T m_data;

13         public TypedNode(T data)

14             : this(data, null)

15         {

16 

17         }

18         public TypedNode(T data, Node next)

19             : base(next)

20         {

21             m_data = data;

22         }

23         public override string ToString()

24         {

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

26         }

27     }

 
テストコード:
            Node head = new TypedNode<Char>('.');

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

            head = new TypedNode<string>(" Today is ", head);

            Console.WriteLine(head.ToString());

 
Codes from