62 492
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #29387 in C++ for curtis

Question #29387
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
Expert's answer
//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);

system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions