鏈表能夠說在數據結構中擁有很普遍的應用數組
它是一個很是好的容器,它和傳統的數組相比較,它具備良好的可變性數據結構
鏈表最基礎的功能是增刪改查,關於查找,C#提供了一種屬性 索引函數函數
而後,它的基本形式以下this
首先 ,咱們應該用一個節點來存儲信息,我使用泛型的節點spa
class Node<T> { public T Data; public Node<T> Next; public Node() { } public Node(T Data) { this.Data = Data; } }
而後即是鏈表code
public delegate bool CompareTool<T>(T a, T b); public delegate void ShowInfo<T>(T a, T b); class LinkList<T> { protected Node<T> Head; protected int _length; public CompareTool<T> CTool; public delegate void ShowInfo<L>(L a); public ShowInfo<T> SI; public T this[int Index] { get => Find(Index); } public int Length { get => _length; } public LinkList() { Head = new Node<T>(); _length = -1; } public LinkList(T a) { Head = new Node<T>(); Head.Next=new Node<T>() { Data=a } _length = 0; } public void Enter(T Ves) { Enter(Ves, -2); } public virtual void Enter(T Ves,int pos) { Node<T> a = new Node<T>(Ves); if (pos == -3)//按序插 { } else if (pos == -2)//插頭 { } else if (pos == -1)//插尾 { } else//指定位置 { } } public virtual T Find(int Index) { } public T Out() { return Out(-2); } public virtual T Out(int pos) { Node<T> temp; if (pos == -2)//刪頭 { } else if (pos == -1)//刪尾 { } else//指定位置 { } _length--; return temp.Data; } public void Serialize() { } public void Deserialize() { } public bool CompareTo(T Value) { return CTool(Head.Data,Value); } public void Show() { Node<T> a = Head; while(a!=null) { SI(a.Data); a = a.Next; } } }