public T GetNext() { LLItem item = this.current; this.current = item.Next; return(item.Value); }
private LLItem GetItem(int index) { LLItem x = this.first; for (int i = 0; i < index; i++) { x = x.Next; } return(x); }
// Enumerator (yield) public IEnumerator <T> GetEnumerator() { LLItem item = this.first; while (item != null) { yield return(item.Value); item = item.Next; } }
public void Add(T value) { LLItem i = new LLItem() { Value = value }; if (this.first == null) { this.first = i; } else { this.last.Next = i; } this.last = i; }
public void RemoveAt(int index) { if (index == 0) { this.first = this.first.Next; if (this.first == null) { this.last = null; } } else { LLItem x = this.GetItem(index - 1); x.Next = x.Next.Next; if (x.Next == null) { this.last = x; } } }
public void Insert(int index, T value) { LLItem n = new LLItem() { Value = value }; if (index > 0) { LLItem x = this.GetItem(index - 1); n.Next = x.Next; x.Next = n; if (n.Next == null) { this.last = n; } } else { n.Next = this.first; this.first = n; } }
public void Clear() { this.first = this.last = null; }
public LLIterator(LLItem item) { this.current = item; }