-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackWithArray.cpp
80 lines (53 loc) · 1.13 KB
/
stackWithArray.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<bits/stdc++.h>
using namespace std;
#define SIZE 100
//eassy
int stck[SIZE],top=-1;
bool isFull(){
if (top+1==SIZE)
return true;
else
return false;
}
bool isEmpty(){
if(top==-1)
return true;
else
return false;
}
void push(int item){
if(isFull())
{
cout<<"Overflow"<<endl;
return;
}
top = top + 1;
stck[top] = item;
}
int pop(){
if(isEmpty()){
cout<<"Underflow"<<endl;
return -1;
}
int item = stck[top];
top = top - 1;
return item;
}
int peek(){
return stck[top];
}
int main(){
for(int i=1;i<=99;i++){
push(10+i);
cout<<"Top: "<<top<<" | stack["<<top<<"]: "<<stck[top]<<endl;
}
cout<<peek()<<endl;
push(0);
cout<<"Top: "<<top<<" | stack["<<top<<"]: "<<stck[top]<<endl;
push(1);
cout<<"Top: "<<top<<" | stack["<<top<<"]: "<<stck[top]<<endl;
cout<<peek()<<endl;
cout<<pop()<<endl;
cout<<"Top: "<<top<<" | stack["<<top<<"]: "<<stck[top]<<endl;
return 0;
}