/// <summary> /// Removes the element from the top of the stack. /// If the stack is empty, throws an InvalidOperationException. /// </summary> /// <returns></returns> public T Pop() { T x = Peek(); _elements = _elements.Next; _count--; return(x); }
/// <summary> /// Removes the element at the front of the queue. /// </summary> /// <returns>The element removed.</returns> public T Dequeue() { T x = Peek(); _front = _front.Next; Count--; return(x); }
}//end peek /// <summary> /// Pop shows and removes the front element in _topStack /// </summary> /// <returns></returns> public T Pop() { T toReturn = Peek(); _topStack = _topStack.Next; _numElements--; return(toReturn); }//end pop
/// <summary> /// Removes the element at the top of the stack. /// </summary> /// <returns>The element removed.</returns> public T Pop() { T x = Peek(); _top = _top.Next; Count--; return(x); }
/// <summary> /// Pushes the given item onto the top of the stack. /// </summary> /// <param name="x">The item to push.</param> public void Push(T x) { LinkedListCell <T> cell = new LinkedListCell <T>(); cell.Data = x; cell.Next = _elements; _elements = cell; _count++; }
}//end count /// <summary> /// push puts new cells into _topStack /// </summary> /// <param name="x"></param> public void Push(T x) { LinkedListCell <T> element = new LinkedListCell <T>(); element.Data = x; element.Next = _topStack; _topStack = element; _numElements++; }//end push
/// <summary> /// Places the given element on the top of the stack. /// </summary> /// <param name="x">The element to push.</param> public void Push(T x) { LinkedListCell <T> cell = new LinkedListCell <T>(); cell.Data = x; cell.Next = _top; _top = cell; Count++; }
/// <summary> /// Returns the value at the front of the queue /// </summary> /// <returns></returns> public T Dequeue() { if (_Count > 0) { T temp = Peek(); _front = _front.Next; _Count--; return(temp); } else { throw new InvalidOperationException(); } }
/// <summary> /// Places the given element at the back of the queue. /// </summary> /// <param name="x">The element to enqueue.</param> public void Enqueue(T x) { LinkedListCell <T> cell = new LinkedListCell <T>(); cell.Data = x; if (Count == 0) { _front = cell; } else { _back.Next = cell; } _back = cell; Count++; }
/// <summary> /// Adds a new link to the list at the back /// </summary> /// <param name="x"></param> public void Enqueue(T x) { LinkedListCell <T> temp = new LinkedListCell <T>(); if (_Count == 0) { _front = temp; _back = temp; } else { _back.Next = temp; _back = temp; } _back.Data = x; _Count++; }