#include "stack.h"

class Stack<ValueType>

This class models a linear structure called a stack in which values are added and removed only from one end. This discipline gives rise to a last-in/first-out behavior (LIFO) that is the defining feature of stacks. The fundamental stack operations are push (add to top) and pop (remove from top).
Constructor
Stack()  O(1) Initializes a new empty stack.
Methods
clear()  O(1) Removes all elements from this stack.
equals(stack)  O(N) Returns true if the two stacks contain the same elements in the same order.
isEmpty()  O(1) Returns true if this stack contains no elements.
peek()  O(1) Returns the value of top element from this stack, without removing it.
pop()  O(1) Removes the top element from this stack and returns it.
push(value)  O(1) Pushes the specified value onto this stack.
size()  O(1) Returns the number of values in this stack.
toString()  O(N) Converts the stack to a printable string representation.
Operators
stack1 == stack1  O(N) Returns true if stack1 and stack2 contain the same elements.
stack1 != stack2  O(N) Returns true if stack1 and stack2 are different.
ostream << stack O(N) Outputs the contents of the stack to the given output stream.
istream >> stack O(N) Reads the contents of the given input stream into the stack.

Constructor detail


Stack();
Initializes a new empty stack.

Usage:

Stack<ValueType> stack;

Method detail


void clear();
Removes all elements from this stack.

Usage:

stack.clear();

bool equals(const Stack& stack) const;
Returns true if the two stacks contain exactly the same element values in the same order. Identical in behavior to the == operator.

Usage:

if (stack.equals(stack2)) ...

bool isEmpty() const;
Returns true if this stack contains no elements.

Usage:

if (stack.isEmpty()) ...

ValueType peek() const;
ValueType& top();
Returns the value of top element from this stack, without removing it. This method signals an error if called on an empty stack. For compatibility with the STL classes, this method is also exported under the name top, in which case it returns the value by reference.

Usage:

ValueType top = stack.peek();

ValueType pop();
Removes the top element from this stack and returns it. This method signals an error if called on an empty stack.

Usage:

ValueType top = stack.pop();

void push(ValueType value);
Pushes the specified value onto this stack.

Usage:

stack.push(value);

int size() const;
Returns the number of values in this stack.

Usage:

int n = stack.size();

string toString() const;
Converts the stack to a printable string representation, with the elements listed left-to-right from the bottom of the stack to the top, such as "{value1, value2, value3}".

Usage:

string str = stack.toString();