public T Pop() { if (this.Count == 0) { throw new InvalidOperationException(); } T current = this.top.Value; this.top = this.top.Next; this.Count--; return(current); }
public void Push(T value) { if (this.Count == 0) { this.lastPushed = new StackNode <T>(value); } else { var newLast = new StackNode <T>(value); newLast.PrevNode = this.lastPushed; this.lastPushed = newLast; } this.Count++; }
public T[] ToArray() { T[] array = new T[this.Count]; StackNode current = this.top; int index = 0; while (current != null) { array[index++] = current.Value; current = current.Next; } return(array); }
public T[] ToArray() { T[] arr = new T[this.Count]; StackNode stackNode = this.top; int index = 0; while (stackNode != null) { arr[index++] = stackNode.Value; stackNode = stackNode.Next; } return(arr); }
public StackNode(T value, StackNode next) { this.Value = value; this.Next = next; }
public void Push(T element) { this.top = new StackNode(element, this.top); this.Count++; }
public void Push(T item) { this.top = new StackNode(item, this.top); this.Count++; }
public void Clear() { this.top = null; Count = 0; }