-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_push_pop.c
More file actions
70 lines (52 loc) · 847 Bytes
/
Stack_push_pop.c
File metadata and controls
70 lines (52 loc) · 847 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
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// main.c
// DataStructure
//
// Created by Pooshan Vyas on 8/19/15.
// Copyright © 2015 Pooshan Vyas. All rights reserved.
//
#include <stdio.h>
#define size 5
int stack [size];
int top = -1; // Because index start from 0
int isEmpty()
{
if (top == -1)
return 1;
else
return 0;
}
int isFull()
{
if (top == size -1)
return 1;
else
return 0;
}
int onTop()
{
return stack[top];
}
void push(int element)
{
if(isFull())
printf("stack is Full\n");
else
{
top++;
stack[top] = element;
}
}
void pop()
{
if(isEmpty()==1)
printf("stack is Empty\n");
else
top--;
}
int main()
{
push(10); push(11); push(101); push(21); push(50);
pop(); pop(); pop();
printf("on the top we have %d \n", onTop());
}