/** * @title: stack2730.cpp * @date: 2004.07.15 - 9:01 pm * @author: vinnie * @ class implementation for the class Stack2730 */ #include #include #include "stack2730.h" using namespace std; // constructor Stack2730::Stack2730( int len, int num, int *moreLen) { numStacks = num; ind = new int[numStacks]; size = new int[numStacks]; stack = new int*[numStacks]; for ( int i = 0; i < numStacks; i++) { ind[i] = 0; if ( !i ) size[i] = len; else size[i] = moreLen[i-1]; stack[i] = new int[size[i]]; } } // destructor Stack2730::~Stack2730( ) { delete []ind; delete []size; for ( int i = 0; i < numStacks; i++) delete []stack[i]; delete []stack; } // returns true if array is empty inline bool Stack2730::empty( int i) { if ( ind[i] ) return false; return true; } // prints out the values stored in the stack. inline bool Stack2730::show( int i) { if ( !ind[i] ) return false; if (!ind[i]) { for ( int j = 0; j < ind[i]; j++) cout << stack[i] << " "; return true; } else { return true; } } // returns true if there is room in that stack inline bool Stack2730::room( int i) { if ( ind[i] < size[i] ) return true; return false; } // returns the number of items in the stack, if any // otherwise fails inline int Stack2730::getArrSize( int i) { return ind[i]; } // returns the number of stacks inline int Stack2730::getNumStacks( ) { return numStacks; } // returns the top item on the stack, if any // otherwise fails inline int Stack2730::top( int i) { if ( ind[i]) return stack[i][ind[i]-1]; return 0; } // returns true if operation succeed inline bool Stack2730::push( int newNum, int i) { if ( ind[i] < (size[i]) ) { stack[i][ind[i]] = newNum; ++ind[i]; return true; } return false; } // removes and returns the top item on the stack, if any // otherwise fails inline int Stack2730::pop( int i) { if ( ind[i] ) { --ind[i]; return stack[i][ind[i]]; } return 0; } // flush inline void Stack2730::flush( int i) { ind[i] = 0; }