-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
111 lines (65 loc) · 1.16 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stack[100],i,j,choice=0,n,top=0;
void push ()
{
int val;
if (top == n-1 )
printf("\nOverflow");
else
{
for (i=0;i<n;i++)
{
scanf("%d",&val);
top ++;
stack[top] = val;
}
}
}
void pop ()
{
if(top == -1)
printf("Underflow");
else
printf("\nThe Poped Element is:%d\n",stack[top]);
top--;
}
void show()
{
printf("The Elements in the stack are:");
for (i=top;i>0;i--)
{
printf("%d ",stack[i]);
}
if(top == -1)
{
printf("Stack is empty");
}
}
int main ()
{
int n1;
scanf("%d",&n);
scanf("%d",&n1);
if(n1>n)
{
printf("No.of.Elements is Higher than the size of the stack");
}
else
{
n=n1;
push();
show();
pop();
show();
}
return 0;
}