-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.c
More file actions
93 lines (82 loc) · 1.38 KB
/
Copy pathstack.c
File metadata and controls
93 lines (82 loc) · 1.38 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#define max 5
struct stack
{
int top;
int a[max];
}s1;
//void push(int *,int);
//int pop(int *);
//int isstackempty(int *);
//int isstackfull(int *);
//void display(int *);
int isstackempty(struct stack *s1)
{
if(s1->top==-1)
return 1;
else
return 0;
}
int isstackfull(struct stack *s1)
{
if(s1->top==(max-1))
return 1;
else
return 0;
}
void push(struct stack *s1,int value)
{
if(isstackfull(s1))
return ;
else
{
s1->top=(s1->top)+1;
s1->a[s1->top]=value;
}
}
int pop(struct stack *s1)
{
if(isstackempty(s1))
return ;
else{
int k=s1->a[s1->top];
s1->top=(s1->top)-1;
return k;
}
}
void display(struct stack *s1)
{
if(s1->top==-1)
{
printf("stack is emty");
}
for( int i=s1->top;i>=0;i--)
{
printf(" the stasj is %d\n",s1->a[i]);
}
}
int main()
{
struct stack *s=&s1;
s->top=-1;
while(1)
{
int u,n,p;
printf("enete 1.pop\n 2.push\n 3.display");
scanf("%d",&u);
switch(u)
{
case 1 :
p=pop(s);
printf("the pop ele is %d",p);
break;
case 2: printf("enter elem tp push");
scanf("%d",&n);
push(s,n);
break;
case 3 :display(s);
}
}
//printf("stack is%d ",T);
return 0;
}