create a program that will perform the following task:
-pop(s) { remove an item/element from the top of stack }
-push(s,i) { to add an element to the top of the stack }
-empty(s) { determine if the stack is empty or not }
-stack top(s) { determine the top element of the stack }
1
Expert's answer
2013-01-23T09:52:59-0500
#include <iostream> using namespace std; class stack{ int m[100]; int head; public: stack(){head=-1;} void push(int a){ head++; m[head] = a; } bool pop(){ if (head >= 0){ head--; return true; } else return false; } bool empty(){ if (head >= 0 ) return true; else return false; } int stackTop(){return m[head];} };
Comments
Leave a comment