Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

3. What should a contract of employment contain?

Answered: 1 week ago

Question

1. What does the term employment relationship mean?

Answered: 1 week ago