-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path54.c
75 lines (67 loc) · 1.28 KB
/
54.c
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
//C Program to implement stack PULL & PUSH Operation through an array.
#include<stdio.h>
#include<stdlib.h>
#define ARRMAX 5
int top = -1; //Meaning stack is currently empty, it is global variable because every function will need it
int stack[ARRMAX];
int i;
void push(int data)
{
top++;
if(top==-1)
{
printf("Stack Underflow!");
return;
}
else if(top==ARRMAX)
{
printf("Stack Overflow!");
return;
}
else
{
stack[top] = data;
printf("Elements of Stack\n");
for(i=0;i<=top;i++)
{
printf("Stack Values %d: %d \n", i, stack[i]);
}
return;
}
}
void pull(int data)
{
if(top==-1)
{
printf("\nStack Underflow!");
return;
}
else if(top==ARRMAX)
{
printf("Stack Overflow!");
return;
}
else
{
stack[top] = data;
top--;
printf("Elements of Stack\n");
for(i=0;i<=top;i++)
{
printf("Stack Values %d: %d \n", i, stack[i]);
}
printf(" ");
return;
}
}
int main()
{
push(5);
push(6);
push(4);
push(3);
push(1);
pull(5);
pull(6);
return 0;
}