0% found this document useful (0 votes)
19 views

1) Stack Array

Uploaded by

lsomesh448
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

1) Stack Array

Uploaded by

lsomesh448
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No:- 01

Practical Name:- Implementation of Stack using Array


Name:- ankush bhakare
Roll No:- 14

#include”iostream.h”
#include”conio.h”
Class Stack
{
Int A[4],top,ele,size;
Public:
Stack();
Void PUSH(int);
Int POP();
Int PEEP();
Void VIEW_ALL();
};
Stack::Stack()
{ Top=
0;
Size=5;
}
Void Stack::PUSH(int ele)
{
If(top==size)
Cout<<”Stack is full!”;
Else
{
Top=top+1;
A[top]=ele;
}
}
Int Stack::POP()
{
Int ele;
If(top==0)
{
Cout<<”Stack is empty”;
Return NULL;
}
Else
{
Ele=A[top];
Top=top-1;
Return ele;
}
}
Int Stack::PEEP()
{
If(top==0)
{
Cout<<”Stack is empty!”;
Return NULL;
}
Else
Return A[top];
}
Void Stack::VIEW_ALL()
{
If(top==0)
{
Cout<<”Stack is empty!”;
}
Else
{
For(int i=top;i>=1;i--)
{
Cout<<A[i]<<endl;
}
}
}
Void MENU()

{ Stack
s;
Int ch,ele;
Do
{
Cout<<”1.PUSH”<<endl;
Cout<<”2.POP”<<endl;
Cout<<”3.PEEP”<<endl;
Cout<<”4.VIEW_ALL”<<endl;
Cout<<”5.EXIT”<<endl;
Cout<<”Enter your choice:”<<endl;
Cin>>ch;
Switch(ch)
{
Case 1:
Cout<<”Enter the elements:”;
Cin>>ele;
s.PUSH(ele);
break;
case 2:
cout<<endl<<s.POP()<<”deleted:”;
break;
case 3:
cout<<endl<<s.PEEP()<<” is the topmost”;
break;
case 4:
cout<<endl<<”The stack element
is:”; s.VIEW_ALL(); break;
case 5:
return;
defalut:
cout<<endl<<”Invalid choice!”;
}
}while(1);
}
Void main()
{
MENU();
}

You might also like