public Type NextNode() //设置下一结点为当前结点 { if (current.Next != null) { current = current.Next; } return(current.Data); }
public void CreateHead(Type[] dt, int n) //头插法生成n个结点 { MakeEmpty(); for (int i = 1; i <= n; i++) { head.Next = new CSListnode <Type>(dt[i - 1], head.Next); } current = head.Next; }
public void CreateRear(Type[] dt, int n) //尾插法生成n个结点 { MakeEmpty(); for (int i = 1; i <= n; i++) { current.Next = new CSListnode <Type>(dt[i - 1]); current = current.Next; } }
public Type Getdata(int i) //返回第i个结点的数据 { CSListnode <Type> p = head; int j = 0; while (p.Next != null && j < i) { p = p.Next; if (++j == i) { break; } } return(p.Data); }
public CSListnode <Type> Getnode(int i) //返回第i个结点的地址 { CSListnode <Type> p = head; int j = 0; while (p.Next != null && j < i) { p = p.Next; if (++j == i) { break; } } return(p); }
public CSListnode <Type> Find(Type value) //按给定值查找单链表 { CSListnode <Type> p = head; while (p.Next != null) { if (p.Data.Equals(value)) { return(p); } else { p = p.Next; } } return(null); }
public void Create(Type[] dt, int n, bool InsertInHead) //生成n个结点 { MakeEmpty(); if (InsertInHead) { for (int i = 1; i <= n; i++) { Insert(dt[i - 1], 1); } } else { for (int i = 1; i <= n; i++) { Insert(dt[i - 1], i); } } current = head; }
public void SetCurrent(CSListnode <Type> cp) { current = cp; } //设置当前指针
private CSListnode <Type> current; //指向当前节点的指针 //-------------------------------------------------------------------------------- public CSList() { head = new CSListnode <Type>(); current = head; }
public CSListnode(Type data, CSListnode <Type> next) { this.data = data; this.next = next; }
public CSListnode(Type data) { this.data = data; next = null; }
public void MakeEmpty() //清空单链表 { head.Next = null; current = head; }
//-------------------------------------------------------------------------------- public CSListnode() { //data=0; next = null; }