public void Append(int DataValue) { ListNode NewNode = new ListNode(DataValue); if (IsNull())//如果头指针为空 { Head = NewNode; Tail = NewNode; } else { Tail.Next = NewNode; NewNode.Previous = Tail; Tail = NewNode; } Current = NewNode; ListCountValue += 1; //链表数据个数加1 }
public void Delete() { if (!IsNull())//若为空链表 { if (IsBof())//若删除头 { Head = Current.Next; Current = Head; ListCountValue -= 1; return; } if (IsEof())//若删除尾 { Tail = Current.Previous; Current = Tail; ListCountValue -= 1; return; } Current.Previous.Next = Current.Next; //若删除中间数据 Current = Current.Previous; ListCountValue -= 1; return; } }
public void Insert(int DataValue) { ListNode NewNode = new ListNode(DataValue); if (IsNull()) { Append(DataValue); //为空表,则添加 return; } if (IsBof()) { //为头部插入 NewNode.Next = Head; Head.Previous = NewNode; Head = NewNode; Current = Head; ListCountValue += 1; return; } //中间插入 NewNode.Next = Current; NewNode.Previous = Current.Previous; Current.Previous.Next = NewNode; Current.Previous = NewNode; Current = NewNode; ListCountValue += 1; }
private ListNode Tail; //尾指针 #endregion Fields #region Constructors //构造函数 public CList() { ListCountValue = 0; //初始化 Head = null; Tail = null; }
public void MovePrevious() { if (!IsBof()) Current = Current.Previous; }
//向后移动一个数据 public void MoveNext() { if (!IsEof()) Current = Current.Next; }
public void MoveLast() { Current = Tail; }
public void MoveFrist() { Current = Head; }