首页 > 代码库 > 泛型链表结构
泛型链表结构
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()); } }
泛型链表结构
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。