You are on page 1of 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