Question #22654

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 }

Expert's answer

#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];}
};

int main(){



return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS