0% found this document useful (0 votes)
37 views2 pages

C++ Pop Push Activity

The document contains code for a C++ program that implements a stack using an array. The program allows the user to push values onto the stack, pop values off the stack, and display the stack contents through a menu-driven interface.

Uploaded by

yenismeee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

C++ Pop Push Activity

The document contains code for a C++ program that implements a stack using an array. The program allows the user to push values onto the stack, pop values off the stack, and display the stack contents through a menu-driven interface.

Uploaded by

yenismeee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include "stdafx.

h"
#include <iostream>

using namespace std;

int stack[100], n=100, top=-1;


void push (int val) {
if (top>n-1)
cout<<"stack overflow"<<endl;
else{
top++;
stack[top]=val;

}
}
void pop () {
if (top<=-1)
cout<<"stack overflow"<<endl;
else{
cout<<"the popped elements if"<<stack[top]<<endl;
top--;
}
void display (){
if (top>0){
cout<<"stack elements are:";
for (int i=top; i>=0); i--)
cout <<stack[i]<<"";
cout<<endl;
}else
cout <<"stack is empty";
}
int main () {
int ch, val;
cout<<"1) Push is stack" << endl;
cout<<"2) pop from the stack" << endl;
cout<<"3) display stack" << endl;
cout<<"4) exit" << endl;
do {
cout<<"Enter Choice" << endl;
cin>>ch;

switch (ch) {
case 1: {
cout<<"enter value to be pushed" << endl;
cin>>val;
push(val);
break;
}
case 2: {
pop();
break;
}
}
case 3: {
display();
break;
}
case 4: {
cout<<"Exit" << endl;
break;
}
default: {
cout<<"invalid choice"<<endl;
}
}
while (ch!=4);
return 0;
}

You might also like