|
|
| version 1.1, 2001/02/21 17:36:30 | version 1.2, 2001/02/22 13:33:24 |
|---|---|
| Line 10 | Line 10 |
| class Stack : public Array { | class Stack : public Array { |
| public: | public: |
| Stack(Pool& apool) : Array(apool), top(0) { | Stack(Pool& apool) : Array(apool), ftop(0) { |
| } | } |
| void push(Item *item) { | void push(Item *item) { |
| if(top<size()) // cell is already allocated? | if(ftop<size()) // cell is already allocated? |
| put(top, item); // use it | put(ftop, item); // use it |
| else | else |
| *this+=item; // append it | *this+=item; // append it |
| top++; | ftop++; |
| } | } |
| Item *pop() { | Item *pop() { |
| return get(--top); | return get(--ftop); |
| } | } |
| Item *operator [] (int top_offset) { | Item *operator [] (int top_offset) { |
| return get(top-top_offset-1); | return get(ftop-top_offset-1); |
| } | } |
| int top() { return ftop; } | |
| private: | private: |
| // deepest used index | // deepest used index |
| int top; | int ftop; |
| }; | }; |