1.using an array of size 10, implement the PUSH and POP operations of the stack. NB: Let your TOP and BOTTOM be -1 when that STACK is EMPTY
2. Convert your algorithm above into a c++ code
1
Expert's answer
2013-05-01T09:05:19-0400
//1.using an array of size 10, implement the PUSH and POP operations of //the stack. NB: Let your TOP and BOTTOM be -1 when that STACK is EMPTY //2. Convert your algorithm above into a c++ code
# include <iostream>
using namespace std;
class stck{
int ar[10]; int ptr; public: stck(){ptr=-1;} void push(int val){ if (ptr == 8) cout<<"Stack is full!\n"; ptr++;ar[ptr] = val;} void pop(){if (ptr == -1) cout<<"Stack is Empty!\n"; else ptr--;} };
int main(){ stck s; s.push(1); s.pop(); s.pop(); for (int i=0;i<11;i++) s.push(1);
Comments
Leave a comment