0% found this document useful (0 votes)
27 views3 pages

1) Stack Array

The document presents a C++ implementation of a stack using an array, detailing the structure and methods for stack operations such as PUSH, POP, PEEP, and VIEW_ALL. It includes a menu-driven interface for user interaction to perform these operations. The code contains some syntax errors and inconsistencies that need correction for proper functionality.

Uploaded by

lsomesh448
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)
27 views3 pages

1) Stack Array

The document presents a C++ implementation of a stack using an array, detailing the structure and methods for stack operations such as PUSH, POP, PEEP, and VIEW_ALL. It includes a menu-driven interface for user interaction to perform these operations. The code contains some syntax errors and inconsistencies that need correction for proper functionality.

Uploaded by

lsomesh448
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/ 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