//构造方法 public CircularList(string Str) { str = Str; _head = new CircularNode(str[0]); int i = 1; CircularNode now, tailTemp; tailTemp = now = _head; while (i < str.Length) { now = new CircularNode(str[i]); i++; now.Next = _head; _head = now; } tailTemp.Next = _head; }
public void Insert(string Str) { int i = 0; CircularNode HeadTemp, tailTemp = _head; while (tailTemp != null && tailTemp.Next != _head) { tailTemp = tailTemp.Next; } while (i < Str.Length) { HeadTemp = _head; _head = new CircularNode(Str[i]); _head.Next = HeadTemp; i++; } tailTemp.Next = _head; }
public override string ToString() { string Str = ""; CircularNode now = _head; if (now == null) { return(Str); } Str += now.Data; now = now.Next; while (now != _head) { Str += now.Data; now = now.Next; } return(Str); }
public void Delete(string Str) { int Times = 0, pTimes = 0; CircularNode HeadTemp, PointTemp, preTemp; preTemp = new CircularNode('0'); HeadTemp = preTemp; preTemp.Next = _head; PointTemp = preTemp.Next; if (PointTemp != null) { for (int j = 0; PointTemp != null && j < Str.Length; j++) { if ((char)PointTemp.Data != Str[j]) { continue; } preTemp.Next = PointTemp.Next; PointTemp = PointTemp.Next; Times++; break; } if (Times > pTimes) { pTimes = Times; } else { preTemp = preTemp.Next; PointTemp = PointTemp.Next; } } while (PointTemp != _head) { for (int j = 0; PointTemp != null && j < Str.Length; j++) { if ((char)PointTemp.Data != Str[j]) { continue; } preTemp.Next = PointTemp.Next; PointTemp = PointTemp.Next; Times++; break; } if (Times > pTimes) { pTimes = Times; continue; } preTemp = preTemp.Next; PointTemp = PointTemp.Next; } if (Times == 0) { MessageBox.Show("不存在所要删除的元素.", "提示", MessageBoxButtons.OK, MessageBoxIcon.None); } _head = HeadTemp.Next; preTemp.Next = _head; for (int j = 0; _head != null && j < Str.Length; j++) { if ((char)_head.Data != Str[j]) { continue; } _head = null; } }