Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack file #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions StackARR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class stack
{
int stk[5];
int top;
public:
stack()
{
top=-1;
}
void push(int x)
{
if(top > 4)
{
cout<<"Stack OverFlow.";
return;
}
stk[++top]=x;
cout <<"Inserted element is: " <<x;
}
void pop()
{
if(top <0)
{
cout <<"Stack UnderFlow.";
return;
}
cout <<"Deleted element is: " <<stk[top--];
}
void topp()
{
{
if(top <0)
{
cout <<"Stack UnderFlow.";
return;
}
cout <<"Element at the top is : " <<stk[top]<<endl;
}
}
void display()
{
if(top<0)
{
cout <<"Stack is Empty.";
return;
}
for(int i=top;i>=0;i--)
cout <<stk[i] <<" ";
}
};
void main()
{
clrscr();
int ch;
stack st;
cout<<"*****Stack Implementation using array*****";
while(1)
{
cout<<"\n1.Push 2.Pop 3.Top 4.Display 5.Exit\nEnter your choice: "<<endl;
cin>>ch;
switch(ch)
{
case 1: cout <<"\nEnter the element to be added: "<<endl;
cin>>ch;
st.push(ch);
break;
case 2: st.pop();
break;
case 3: st.topp();
break;
case 4: st.display();
break;
case 5: exit(0);
}
}
getch();
}