#include<conio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
class SStack
{
private:
int *arr=NULL;
int top=0;
public:
SStack(int size)
{
arr=new int[size];
}
SStack()
{
arr=new int[5];
}
void push(int x)
{
if(top>5)
{
cout<<"stack is full";
return;
}
arr[top++]=x;
cout<<"successfully inserted:"<<x;
}
void pop()
{
if(top<0)
{
cout<<"stack is empty";
return;
}
cout<<"the deleted item is:"<<arr[top--];
}
void display()
{
if(top<0)
{
cout<<"the stack is empty";
return;
}
for(int i=top;i>=0;i--)
cout<<arr[i]<<" ";
}
};
int main()
{
int ch;
SStack *stk=new SStack[10];
SStack st;
while(1)
{
cout<<"\n press 1 to push \n press 2 to pop \n press 3 to display \n 4 to exit";
cin>>ch;
switch(ch)
{
case 1:cout<<"enter the element";
cin>>ch;
st.push(ch);
break;
case 2:st.pop();
break;
case 3:st.display();
break;
case 4:exit(0);
}
}
return(0);
}
Hasheeb 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.