-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-array.c
More file actions
51 lines (51 loc) · 905 Bytes
/
stack-array.c
File metadata and controls
51 lines (51 loc) · 905 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
#include<stdio.h>
#define MAX_SIZE 100
int A[MAX_SIZE]; //Global pointer so that i can use this one everywhere in every function
int top=-1; //Global variable to point at the top of the stack
void push(int x){
if(top==MAX_SIZE-1){
printf("STACK OVERFLOW\n");
return;
}
else {
top= top+1;
A[top]=x;
}
}
void pop(){
if(top==-1){
printf("Nothing to remove::\n Stack underflow");
}
else{
top=top-1;
}
}
int isempty(){
if(top==-1){
return 1;
}
else{
return 0;
}
}
int peek(){
return A[top];
}
void print(){
for(int i=0; i<=top; i++){
printf("%d\n", A[i]);
}
}
int main(){
int y;
push(2);
print();
push(9);
print();
push(13);
print();
pop();
print();
y= peek();
printf("%d", y);
}