码迷,mamicode.com
首页 > 其他好文 > 详细

泛型链表结构

时间:2016-11-24 06:53:53      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:泛型链表   line   link   多个   data   sam   表结构   cte   his   

internal sealed class Node<T>
    {
        public T m_data;
        public Node<T> m_next;

        public Node(T data) : this(data, null)
        {
        }

        public Node(T data, Node<T> next)
        {
            m_data = data;
            m_next = next;//存储上一个Node<T>结构
        }

        public override string ToString()
        {
            return m_data.ToString() + ((m_next != null) ? m_next.ToString() : null);
        }

        public static void SameDataLinkedList()
        {
            Node<char> head = new Node<char>(C);
            head = new Node<char>(B, head);
            head = new Node<char>(A, head);
            Console.WriteLine(head.ToString());
        }

    }
}

同时存储多个类型的链表

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

        public static void SameDataLinkedList()
        {
            Node head = new TypeNode<char>(.);
            head = new TypeNode<DateTime>(DateTime.Now, head);
            head = new TypeNode<string>("Today to", head);
            Console.WriteLine(head.ToString());
        }

    }

 

泛型链表结构

标签:泛型链表   line   link   多个   data   sam   表结构   cte   his   

原文地址:http://www.cnblogs.com/Tan-sir/p/6035873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!