Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/classcasa_1_1Stack.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 20:10:15 2011 Кодировка: Поисковые слова: photosphere |
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. | |
Stack (const Stack< elem > &other) | |
Create a stack by making a copy of other. | |
Stack< elem > & | operator= (const Stack< elem > &other) |
Create a stack which is a copy of other. | |
~Stack () | |
void | push (const elem &e) |
Add an element to the top of the stack. | |
void | pop () |
Remove the top element from the top of the stack. | |
elem | popVal () |
Remove the top element from the top of the stack, and return it. | |
elem & | top () |
Retreive the top element on the stack. | |
const elem & | top () const |
Bool | empty () const |
Check to see if the stack is empty. | |
Private Attributes | |
Link< elem > * | topOfStack |
Pointer to the top of the stack. |
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.
Stack<int> one,two; int count = 0; one.push(1); // add one.push(2); // add one.push(3); // add one.push(4); // add while ( !one.empty() ) { cout << one.top() << " "; // top element two.push(one.top()); // push = add one.pop(); // remove top element } cout << endl; while ( !two.empty() ) { one.push(two.top()); cout << two.popVal() << " "; // remove and return top } while ( !one.empty() ) count += one.popVal(); cout << endl << count << endl;;
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.
Definition at line 101 of file Stack.h.
casa::Stack< elem >::Stack | ( | ) | [inline] |
casa::Stack< elem >::Stack | ( | const Stack< elem > & | other | ) |
Create a stack by making a copy of other.
casa::Stack< elem >::~Stack | ( | ) |
Bool casa::Stack< elem >::empty | ( | ) | const [inline] |
Check to see if the stack is empty.
Definition at line 171 of file Stack.h.
References casa::False, casa::Stack< elem >::topOfStack, and casa::True.
Stack<elem>& casa::Stack< elem >::operator= | ( | const Stack< elem > & | other | ) |
Create a stack which is a copy of other.
void casa::Stack< elem >::pop | ( | ) | [inline] |
Remove the top element from the top of the stack.
Definition at line 132 of file Stack.h.
References casa::throw_empty_Stack_error(), casa::Stack< elem >::topOfStack, and casa::Link< t >::unlink().
elem casa::Stack< elem >::popVal | ( | ) | [inline] |
Remove the top element from the top of the stack, and return it.
Definition at line 143 of file Stack.h.
References casa::throw_empty_Stack_error(), casa::Stack< elem >::topOfStack, casa::Link< t >::unlink(), and casa::Link< t >::val().
void casa::Stack< elem >::push | ( | const elem & | e | ) | [inline] |
Add an element to the top of the stack.
Definition at line 127 of file Stack.h.
References casa::Stack< elem >::topOfStack.
const elem& casa::Stack< elem >::top | ( | ) | const [inline] |
Definition at line 162 of file Stack.h.
References casa::throw_empty_Stack_error(), and casa::Stack< elem >::topOfStack.
elem& casa::Stack< elem >::top | ( | ) | [inline] |
Retreive the top element on the stack.
Definition at line 157 of file Stack.h.
References casa::throw_empty_Stack_error(), and casa::Stack< elem >::topOfStack.
Link<elem>* casa::Stack< elem >::topOfStack [private] |
Pointer to the top of the stack.
Definition at line 104 of file Stack.h.
Referenced by casa::Stack< elem >::empty(), casa::Stack< elem >::pop(), casa::Stack< elem >::popVal(), casa::Stack< elem >::push(), and casa::Stack< elem >::top().