#include #include class Istack { int sz; int top; int* stack; public: // member function prototypes void init(int ); void push(int ); int pop(); bool isempty(); bool isfull(); }; /* class Pstack { class node { public: int data; node* next; }; node* new_node(int , node* ); node* top; public: // Note that the stack is implicit void init(int nitems ); void push(int x); int pop(); bool isempty(); bool isfull(); }; */ // Array implementation of stacks. // Grow from high index towards 0. void Istack :: init(int nitems = 100) { sz = nitems; stack = new int[sz]; top = sz; } void Istack :: push(int x) { assert( !isfull() ); stack[--top] = x; } int Istack :: pop() { assert( !isempty() ); return( stack[top++] ); } bool Istack :: isempty() { return( top == sz ); } bool Istack :: isfull() { return( top == 0 ); } class TestType { private: int num1, num2; float real1; public: TestType(int Num1Start, float Real1Start = 3.14) : num1(Num1Start), real1(Real1Start) { cout << num1 << " " << num2 << " " << real1 << endl; } }; class TestNew { private: int x ; public: TestNew() {} // Do nothing, but what about x? }; main() { Istack s1, s2; int i; // TestType Object1; // no constructor with no params TestType Object2(32, 9.45); TestType Object3(42); // one default parameter // TestType Object4(52, 7.43, 12); // no constructor with 3 params TestNew ObjectNew; int ArraySize = 64; // float Array[ArraySize]; // ArraySize must be a const float* Array1 = new float[ArraySize]; cout << "start execution" << endl; s1.init(500); s2.init(); for( i = 0; i < 20; i++ ) { s1.push(i); } for( i = 0; i < 20; i++ ) { cout << s1.pop() << ' '; } cout << endl; s2.push(10); i = s2.pop(); } /* 32 1597 9.45 // why "1597"? 42 1207960588 3.14 // why "1207960588"? start execution 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */