-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_ArrayImplementation.c
More file actions
61 lines (59 loc) · 885 Bytes
/
Copy pathStack_ArrayImplementation.c
File metadata and controls
61 lines (59 loc) · 885 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
// Stack - Array based implementation.
// Creating a stack of integers.
#include <stdio.h>
#define MAX_SIZE 101
int A[MAX_SIZE];
int top = -1;
void Push(int x)
{
if (top == MAX_SIZE - 1)
{
printf("Error: stack overflow\n");
return;
}
printf("Push number is %d\n", x);
A[++top] = x;
}
void Pop()
{
if (top == -1)
{
printf("Error: No element to pop\n");
return;
}
printf("Now pop the number %d\n", A[top]);
top--;
}
int Top()
{
return A[top];
}
int IsEmpty()
{
if (top == -1)
return 1;
return 0;
}
void Print()
{
printf("stack : ");
for (int i = 0; i <= top; i++)
{
printf("%d ", A[i]);
}
putchar('\n');
}
int main()
{
Push(2);
Print();
Push(5);
Print();
Push(10);
Print();
Pop();
Print();
Push(12);
Print();
return 0;
}