Last change
on this file since 80 was
80,
checked in by Sam Hocevar, 14 years ago
|
- Adding the Golgotha source code. Not sure what's going to be interesting
in there, but since it's all public domain, there's certainly stuff to
pick up.
|
-
Property svn:keywords set to
Id
|
File size:
1.2 KB
|
Rev | Line | |
---|
[80] | 1 | /**********************************************************************
|
---|
| 2 | *<
|
---|
| 3 | FILE: stack.h
|
---|
| 4 |
|
---|
| 5 | DESCRIPTION: Simple stack using Tab.
|
---|
| 6 |
|
---|
| 7 | CREATED BY: Rolf Berteig
|
---|
| 8 |
|
---|
| 9 | HISTORY: Created 22 November 1994
|
---|
| 10 |
|
---|
| 11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
| 12 | **********************************************************************/
|
---|
| 13 |
|
---|
| 14 | #ifndef __STACK__
|
---|
| 15 | #define __STACK__
|
---|
| 16 |
|
---|
| 17 | template<class T> class Stack {
|
---|
| 18 | private:
|
---|
| 19 | Tab<T> s;
|
---|
| 20 |
|
---|
| 21 | public:
|
---|
| 22 | // access the stack indexing from the top down.
|
---|
| 23 | T& operator[](const int i) const {
|
---|
| 24 | assert(s.Count()-i>0);
|
---|
| 25 | return s[s.Count()-i-1];
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | void Push( T *el ) {
|
---|
| 29 | s.Append( 1, el );
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void Pop( T *el ) {
|
---|
| 33 | assert( s.Count() );
|
---|
| 34 | *el = s[s.Count()-1];
|
---|
| 35 | s.Delete( s.Count()-1, 1 );
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | void Pop() {
|
---|
| 39 | assert( s.Count() );
|
---|
| 40 | s.Delete( s.Count()-1, 1 );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void GetTop( T *el ) {
|
---|
| 44 | assert( s.Count() );
|
---|
| 45 | *el = s[s.Count()-1];
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void Clear() {
|
---|
| 49 | s.Delete(0,s.Count());
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | int Count() {
|
---|
| 53 | return s.Count();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | int Remove( int i ) {
|
---|
| 57 | assert(i<s.Count());
|
---|
| 58 | return s.Delete(s.Count()-1-i,1);
|
---|
| 59 | }
|
---|
| 60 | };
|
---|
| 61 |
|
---|
| 62 | #endif // __STACK__
|
---|
| 63 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.