-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
53 lines (42 loc) · 647 Bytes
/
stack.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
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int top = -1, array[SIZE];
int isFull()
{
return top == SIZE-1;
}
int isEmpty()
{
return top == -1;
}
void push(int no)
{
if(!isFull())
array[++top] = no;
else
printf("Stack if Full \n");
}
int pop()
{
if(!isEmpty())
return array[top--];
else
printf("Stack is empty \n");
}
int peek()
{
return array[top];
}
int main()
{
push(1);
push(2);
push(3);
push(4);
push(5);
printf("PEEK VALUE IS: %d \n",peek());
while(!isEmpty())
printf("POPPED value is: %d \n",pop());
return 0;
}