public CircularList(ICollection <CircularListEntry> col) { CircularListEntry help = new CircularListEntry(); First = help; foreach (CircularListEntry entry in col) { help.Value = entry.Value; help.Key = entry.Key; help.Next = new CircularListEntry(); help = help.Next; } //help = First; }
public void Add(CircularListEntry entry) { if (First != null) { CircularListEntry help = this.SearchKey(Count - 1); help.Next = entry; entry.Next = First; entry.Key = help.Key + 1; } else { First = entry; First.Key = 0; First.Next = First; } }
public override string ToString() { if (First != null) { string ans = ""; CircularListEntry help = First; ans += First.ToString() + " "; help = help.Next; while (help.Key != First.Key) { ans += help.ToString() + " "; help = help.Next; } return(ans); } else { return("Список пуст"); } }
public void Remove(CircularListEntry entry) { if (First != null) { CircularListEntry help = First; if (help.Value != entry.Value) { CircularListEntry last = help; help = help.Next; while (help.Key != First.Key) { if (help.Value == entry.Value) { last.Next = help.Next; for (int i = help.Key; i < Count - 1; i++) { help = help.Next; help.Key = i; } break; } else { last = help; help = help.Next; } } } else { this.SearchKey(this.Count - 1).Next = help.Next; First = help.Next; First.Key = 0; for (int i = 0; i < Count - 1; i++) { help = help.Next; help.Key = i; } } } }
public CircularListEntry SearchKey(int key) { CircularListEntry help = First; if (key == help.Key) { return(help); } help = help.Next; while (help.Key != First.Key) { if (key == help.Key) { return(help); } else { help = help.Next; } } return(null); }
public CircularList(CircularListEntry first) { First = first; }
public CircularListEntry(int value) { Value = value; Next = null; }
public CircularListEntry() { Key = 0; Value = 0; Next = null; }