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

Simple Stack Implementation in C++

The document contains a C++ implementation of a stack data structure with basic operations such as push, pop, check if empty, and check if full. It uses an array to store stack elements and provides a user interface for interacting with the stack through a menu. The implementation has some logical errors, such as incorrect handling of the stack's full condition and missing break statements in the switch cases.

Uploaded by

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

Simple Stack Implementation in C++

The document contains a C++ implementation of a stack data structure with basic operations such as push, pop, check if empty, and check if full. It uses an array to store stack elements and provides a user interface for interacting with the stack through a menu. The implementation has some logical errors, such as incorrect handling of the stack's full condition and missing break statements in the switch cases.

Uploaded by

ali yousaf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<iostream>

using namespace std;


int arr[4];
int top=-1;
class stack
{
public:
void create(int v)
{
cout<<"Push : "<<v<<"From "<<top<<endl;
arr[top]=v;
}
void pop()
{
cout<<"POP : "<<arr[top]<<endl;
}
void empty()
{
if(top==-1)
{
cout<<"Stack is empty"<<endl;
}
}
void isfull()
{
if(top<=5)
{
cout<<"Stack is Full"<<endl;
}
else
{
cout<<"Stack is not full"<<endl;
}
}
};
int main()
{
stack obj;
int choice,v;
while(true)
{
cout<<"\nEnter [Link] Push"<<endl;
cout<<"Enter [Link] pop"<<endl;
cout<<"Enter [Link] Display"<<endl;
cout<<"Enter [Link] empty "<<endl;
cout<<"Enter [Link] full"<<endl;
cin>>choice;
switch(choice)
{
case 1:
if(top<5)
{
cout<<"Enter value"<<endl;
cin>>v;
top++;
[Link](v);
break;
}
else
{
cout<<"List is Full"<<endl;
}
break;
case 2:
if(top>-1)
{
top--;
[Link]();
break;
}
else
{
cout<<"List is Empty"<<endl;
}
case 3:
for(int i=0;i<=top;i++)
{
cout<<arr[i]<<" ";
}
break;
case 4:
[Link]();
break;
case 5:
[Link]();
break;
}
}
}

You might also like