//Syed Rais Ahmad. //CIS:610 Dynamic Data Struc. //Assignment # 5 Question # 1a //Empty, push,pop,popandtest using array #include #define MAX 32 class Stack { private: int * data; //data value in stack unsigned sp; // Stack Pointer unsigned spMax; //Max Stack Pointer Value; public: Stack() ; void push(int ); int pop(); int popNTest() ; int StackTop(); bool Empty(void); }; //Constructor Stack::Stack() { data=new int(MAX); //init data sp=0; //Stack initialized spMax=MAX-1; data[0]=NULL; } //push void Stack::push(int item) { data[++sp]=item; } int Stack::pop() { return data[sp--]; } //Return the Top most element of stack and decrement the SP int Stack::popNTest() { if (sp>0) return data[sp--]; else return -1; } //Is stack empty? bool Stack::Empty() { return (sp)? false : true; } main() { Stack s; s.push(9); s.push(11); cout << "\nPushed 9,11. Pop = " << s.pop(); cout << "\nEmpty() returns:" << s.Empty(); cout << "\npopNTest() returns: " << s.popNTest() ; cout << "\nEmpty() returns:" << s.Empty() << '\n'; return 0; }