Question: c++ Program to Implement stack through classes and objects #include #define SIZE 10 using namespace std; class Stack { int stack[SIZE],top; public: Stack() //Constructor for

c++ Program to Implement stack through classes and objects #include

#define SIZE 10

using namespace std;

class Stack

{

int stack[SIZE],top;

public:

Stack() //Constructor for initializing top

{

top=-1;

}

void push(int num)

{

if(top==SIZE-1) //Stack is full

{

cout<<" STACK OVERFLOW";

}

else

{

top++;

stack[top]=num;

}

}

void pop()

{

int num;

if(top==-1) //Stack is empty

{

cout<<" STACK UNDERFLOW";

}

else

{

num=stack[top];

top--;

cout<<" ELEMENT DELETED: "<

}

}

void traverse()

{

if(top==-1)

{

cout<<" STACK IS EMPTY";

}

else

{

cout<<" STACK ELEMENTS ";

for(int i=top;i>=0;i--)

{

cout<

}

}

}

};

int main()

{

Stack s;

s.traverse();

s.push(10);

s.push(20);

s.push(30);

s.traverse();

s.pop();

s.traverse();

return 0;

}

Every line in this code please explain.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!