-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstack.cpp
51 lines (51 loc) · 833 Bytes
/
stack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#define max 5
using namespace std;
class stack{
int arr[max];
int top_index;
public:
stack(){
top_index=-1;
}
int isEmpty(){
if(top_index==-1)
return 1;
else
return 0;
}
int isFull(){
if(top_index>=max-1)
return 1;
else
return 0;
}
void push(int element){
if (isFull()==0){
top_index++;
arr[top_index]=element;
}
else
cout<<"Stack Overflowed"<<endl;
}
int pop(){
if(isEmpty()==0){
int poped=arr[top_index];
top_index--;
return poped;
}
else
cout<<"Stack Underflow"<<endl;
}
void display(){
if(isEmpty()==0){
int i;
for(i=0;i<=top_index;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
else
cout<<"Stack Underflow"<<endl;
}
};