# 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

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;

}

//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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment