// // Basic Summary: clasical stack // // Implementation file for stack definition // // Copyright: // // Copyright 1993 Ron Burback // Copyright 1993 Objects Plus // All rights reserved // // Description: based on dynamic arrays // // Include files: // #include "stack.h" // // define the version of this structure // char * stack::version = "Objects Plus Stack Version 1.0" ; // // function: stack // parameters: none // goal: basic constructor // returns: new element // stack::stack() {}; // // function: ~stack // parameters: none // goal: basic destructor // returns: element to the heap // stack::~stack() {}; // // function: push // parameters: the element // goal: push an element at the top of the stack // returns: modified stack // void stack::push(void * e) {set(0,e);} // // function: pop // parameters: none // goal: get the element at the top of the stack // returns: the element and a modified stack // void * stack::pop() {return get(0) ; } ; // // function: peak // parameters: none // goal: look at the element at the top of the stack // returns: the element, with out effecting the stack // void * stack::peak() {return dynamic_array::peak(0) ; } ; // // function: QA test // parameters: none // goal: self test of stack, should return true, with no memory creap // returns: true/false // Boolean stack::test() { Boolean results = true ; natural limit = 200 ; natural l ; stack * s ; // store a bunch of unique numbers s = new stack(); for(int i=0;i<=limit;i++){ s->push((void *)i); } // verify the stack works for(i=limit;i>=0;i--){ results &= (void *)i == s->pop(); } delete s ; // done return results ; }