-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
43 lines (31 loc) · 919 Bytes
/
stack.c
File metadata and controls
43 lines (31 loc) · 919 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
#include <stdio.h>
int main() {
int stack[8]; int stack2[8];
int top1 = -1; int top2 = -1;
void pop(int *topvar, int stack[]) {
int data;
if(*topvar!=-1) {
data = stack[*topvar];
*topvar = *topvar - 1;
printf("\nPopped out: %d",data);
printf("\nTop now at: %d", *topvar);
} else {
printf("\nStack is empty.\n");
}
}
void push(int data, int *topvar, int stack[]) {
if(*topvar!=8) {
*topvar = *topvar + 1;
stack[*topvar] = data;
printf("\nInserted successfully: %d", data);
printf("\nTop now at: %d", *topvar);
} else {
printf("Stack is full.\n");
}
}
push(20, &top1, stack);
push(21, &top1, stack);
push(25, &top1, stack);
push(25, &top1, stack);
return 0;
}