-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_1.cpp
More file actions
62 lines (48 loc) · 784 Bytes
/
stack_1.cpp
File metadata and controls
62 lines (48 loc) · 784 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define MAX_SIZE 20
int A[MAX_SIZE];
int top =-1;
void Push(int x){
if(top == MAX_SIZE-1){
cout << "Error: Stack Overflow" <<endl;
return;
}
A[++top] = x;
}
void Pop(){
if (top == -1)
{
cout << "Error : No element to pop" <<endl;
return;
}
top--;
}
int Top(){
return A[top];
}
int isEmpty(){
if(top == -1){
return 1;
}
return 0;
}
void Print(){
cout << "Stack : ";
for (int i = 0; i <=top; i++)
{
cout << A[i] << " ";
}
cout << endl;
}
int main() {
for (int i = 0; i < 20; i++)
{
Push(i); Print();
}
for (int i = 0; i < 20; i++)
{
Pop(); Print();
}
return 0;
}