public SimpleListItem <T> GetItem(int number) { if ((number < 0) || (number >= Count)) { throw new Exception("Выход за границу индекса"); } SimpleListItem <T> current = first; int i = 0; while (i < number) { current = current.next; i++; } return(current); }
public void Add(T element) { var newItem = new SimpleListItem <T>(element); this.Count++; if (last == null) { first = newItem; last = newItem; } else { last.next = newItem; last = newItem; } }
public T Pop() { T current = default(T); if (Count == 0) { return(current); } if (Count == 1) { current = first.data; first = null; last = null; } else { SimpleListItem <T> newLast = GetItem(Count - 2); current = newLast.next.data; last = newLast; newLast.next = null; } Count--; return(current); }