Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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) {

#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(40);

s.push(50);

s.push(60);

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

Step: 3

blur-text-image

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

What are the main goals of the World Trade Organization?

Answered: 1 week ago

Question

33. If the pdf of a measurement error X is f(x) , show that

Answered: 1 week ago