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

Create stack.cpp #279

Open
wants to merge 1 commit into
base: main
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
75 changes: 75 additions & 0 deletions C++/stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include<iostream>
using namespace std ;
#define max 20
class stack
{
int stck[max] ;
int top ;
public :
void init() ;
void push(int i) ;
void pop() ;
void display() ;
};
void stack::init()
{
top=0;
}
void stack::push(int i)
{

if(top==max-1)
{
cout<<"Stack is full\n" ;
}
else
{
top++ ;
stck[top]= i ;
}
}
void stack::pop()
{
int x ;
if(top==0)
{
cout<<"Stack is empty\n" ;
}
else
{
x=stck[top] ;
top--;
cout<<"Deleted element is:"<<x ;
}
}
void stack::display()
{
if(top==-1)
{
cout<<"Stack is empty\n" ;
}
else
{
cout<<"Elements in the stack are\n" ;
while(top>=0)
{
cout<<stck[top] ;
top--;
}
}
}
int main()
{
stack stack1 ;
stack1.push(20) ;
stack1.push(28) ;
stack1.push(89) ;
stack1.push(67) ;

stack1.pop() ;


stack1.display() ;

return 0 ;
}