0% found this document useful (0 votes)
208 views4 pages

Implement Push, Pop Operation of A Stack Using Arrays

This C++ program implements push and pop operations on a stack using arrays. It defines a Stack class with methods to initialize the stack, add elements using push, and remove elements using pop. The main function declares a Stack object, takes user input to perform push or pop operations, and exits when the user chooses.

Uploaded by

Babu
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)
208 views4 pages

Implement Push, Pop Operation of A Stack Using Arrays

This C++ program implements push and pop operations on a stack using arrays. It defines a Stack class with methods to initialize the stack, add elements using push, and remove elements using pop. The main function declares a Stack object, takes user input to perform push or pop operations, and exits when the user chooses.

Uploaded by

Babu
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/ 4

IMPLEMENT PUSH,POP OPERATION OF A STACK USING ARRAYS

#include<iostream.h>

#include<conio.h>

#define MAX 100

class Stack{

public:

int stack[MAX],top,n;

Stack(){

top=-1;

n=0;

void size(){

cout<<"Enter stack size :";

cin>>n;

void push(int data){

top++;

stack[top]=data;

void pop(){

int item;

if(top==-1){

cout<<"\nStack is empty...";

else{

item=stack[top];

top--;
cout<<"\nThe Deleted Item is :"<<item;

};

void main(){

Stack s;

int data,ch;

char ex;

clrscr();

s.size();

do{

cout<<"\n\n1.Push..\n2.Pop..\n3.Exit..\nEnter Your Choice :";

cin>>ch;

switch(ch)

case 1:

if(s.top==s.n-1)

cout<<"\nStack Overflow...";

else

cout<<"\nEnter Insert element on to the Stack..";

cin>>data;

s.push(data);

}
break;

case 2:

s.pop();

break;

case 3:

cout<<"\nAre you sure you want to exit from stack operations...?(Y/N)";

cin>>ex;

break;

default:

cout<<"Choice is Invalid...";

}while((ex!='Y')&&(ex!='y'));

getch();

}
OUTPUT

You might also like