-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.c
More file actions
50 lines (44 loc) · 752 Bytes
/
stack.c
File metadata and controls
50 lines (44 loc) · 752 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
#include <stdio.h>
#define SIZE 5
int arr[SIZE];
void push(int val);
void pop(void);
int top = -1;
int main()
{
printf("Hello, World!\n");
printf("Enter value\n");
push(1);
push(2);
push(3);
push(4);
push(5);
push(6);
push(7);
pop();
push(6);
pop();
push(7);
return 0;
}
void push(int val){
if(top == SIZE -1){
printf("stack is over FLOW\n");
}
else{
top++;
arr[top] = val;
printf("item inserted at %d is %d\n", top , val);
}
}
void pop(void){
int val;
if(top == -1){
printf("stack is under FLOW\n");
}
else{
printf("item remove at %d is %d\n", top, val);
val = arr[top];
top--;
}
}