casacore
|
This class, Stack<t>, defines an implementation of a stack using the doubly linked list primitive, Link<t>. More...
#include <Stack.h>
Public Member Functions | |
Stack () | |
This creates an empty stack. More... | |
Stack (const Stack< elem > &other) | |
Create a stack by making a copy of other. More... | |
Stack< elem > & | operator= (const Stack< elem > &other) |
Create a stack which is a copy of other. More... | |
~Stack () | |
void | push (const elem &e) |
Add an element to the top of the stack. More... | |
void | pop () |
Remove the top element from the top of the stack. More... | |
elem | popVal () |
Remove the top element from the top of the stack, and return it. More... | |
elem & | top () |
Retreive the top element on the stack. More... | |
const elem & | top () const |
Bool | empty () const |
Check to see if the stack is empty. More... | |
Private Attributes | |
Link< elem > * | topOfStack |
Pointer to the top of the stack. More... | |
This class, Stack<t>, defines an implementation of a stack using the doubly linked list primitive, Link<t>.
It has the standard push and pop operations.
A Last-In-First-Out (LIFO) data structure.
A Stack as implemented here is a simple container which can grow with time, and which returns its elements (only) in the inverse order which they are inserted. That is, the fundamental operations are to push (add) an element onto the top of the stack and to pop (remove) an element from the top of the stack. As a result, the last element placed on the stack will be the first element removed.
This results in the following output:
4 3 2 1 1 2 3 4 10
Presently, this implementation is rather simple. It is built directly upon the Link class.
A simple stack was needed for the (now deprecated) CanDelete class.
|
inline |
casacore::Stack< elem >::Stack | ( | const Stack< elem > & | other | ) |
Create a stack by making a copy of other.
casacore::Stack< elem >::~Stack | ( | ) |
|
inline |
Check to see if the stack is empty.
Definition at line 175 of file Stack.h.
References casacore::False, casacore::Stack< elem >::topOfStack, and casacore::True.
Stack<elem>& casacore::Stack< elem >::operator= | ( | const Stack< elem > & | other | ) |
Create a stack which is a copy of other.
|
inline |
Remove the top element from the top of the stack.
Definition at line 136 of file Stack.h.
References casacore::throw_empty_Stack_error(), casacore::Stack< elem >::topOfStack, and casacore::Link< t >::unlink().
|
inline |
Remove the top element from the top of the stack, and return it.
Definition at line 147 of file Stack.h.
References casacore::throw_empty_Stack_error(), casacore::Stack< elem >::topOfStack, casacore::Link< t >::unlink(), and casacore::Link< t >::val().
|
inline |
Add an element to the top of the stack.
Definition at line 131 of file Stack.h.
References casacore::C::e, and casacore::Stack< elem >::topOfStack.
|
inline |
Retreive the top element on the stack.
Definition at line 161 of file Stack.h.
References casacore::throw_empty_Stack_error(), and casacore::Stack< elem >::topOfStack.
|
inline |
Definition at line 166 of file Stack.h.
References casacore::throw_empty_Stack_error(), and casacore::Stack< elem >::topOfStack.
|
private |
Pointer to the top of the stack.
Definition at line 108 of file Stack.h.
Referenced by casacore::Stack< elem >::empty(), casacore::Stack< elem >::pop(), casacore::Stack< elem >::popVal(), casacore::Stack< elem >::push(), and casacore::Stack< elem >::top().