class Stack<ValueType>
push
(add to top) and pop
(remove from top).
Constructor | ||
O(1) | Initializes a new empty stack. | |
Methods | ||
O(1) | Removes all elements from this stack. | |
O(N) | Returns true if the two stacks contain the same elements in the same order. |
|
O(1) | Returns true if this stack contains no elements. |
|
O(1) | Returns the value of top element from this stack, without removing it. | |
O(1) | Removes the top element from this stack and returns it. | |
O(1) | Pushes the specified value onto this stack. | |
O(1) | Returns the number of values in this stack. | |
O(N) | Converts the stack to a printable string representation. | |
Operators | ||
O(N) | Returns true if stack1 and stack2 contain the same elements. |
|
O(N) | Returns true if stack1 and stack2 are different. |
|
O(N) | Outputs the contents of the stack to the given output stream. | |
O(N) | Reads the contents of the given input stream into the stack. |
Stack();
Usage:
Stack<ValueType> stack;
void clear();
Usage:
stack.clear();
bool equals(const Stack& stack) const;
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;
true
if this stack contains no elements.
Usage:
if (stack.isEmpty()) ...
ValueType peek() const; ValueType& top();
top
, in which case it returns the value
by reference.
Usage:
ValueType top = stack.peek();
ValueType pop();
Usage:
ValueType top = stack.pop();
void push(ValueType value);
Usage:
stack.push(value);
int size() const;
Usage:
int n = stack.size();
string toString() const;
"{value1, value2, value3}"
.
Usage:
string str = stack.toString();