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