-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaticStack
More file actions
70 lines (64 loc) · 1.28 KB
/
Copy pathStaticStack
File metadata and controls
70 lines (64 loc) · 1.28 KB
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
#include <stdio.h>
#define size 5
int stack[size];
int top = -1;
// Push => insert the new element at top end.
void push(int value)
{
if ( top == size-1) // If top == size-1, means stack is full
{
printf("stack is full \n");
}
else
{
// increment the top
top++;
//And store value into stack at top
stack[top] = value;
}
}
// Pop => delete the topmost element from stack
void pop()
{
if ( top == -1 ) // If top == -1, means stack is empty
{
printf("Stack is empty \n");
}
else
{
printf("Deleted element : %d\n", stack[top]); //Display deleted element
top--; // Decrement top
}
}
void displayStack()
{
int i;
if ( top == -1 ) // If top == -1, means stack is empty
{
printf("Stack is empty");
}
else
{
printf("Stack is : \n");
i = top; // copy top into i
while ( i >= 0 )
{
printf(" %d \n",stack[i]);
i--;
}
}
}
int main()
{
push(10);
push(20);
push(30);
displayStack();
pop();
displayStack();
pop();
pop();
pop();
displayStack();
return 0;
}