-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathstack_sandy.c
99 lines (83 loc) · 1.3 KB
/
stack_sandy.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
#include<stdio.h>
#include<stdlib.h>
void push();
struct stack* creatstack();
void display();
struct stack
{
int info;
struct stack *link;
};
struct stack *start = NULL;
int count=0;
struct stack* creatstack()
{
struct stack *p;
p=malloc(sizeof(struct stack));
return (p);
}
void pop();
void push()
{
struct stack *temp;
temp = creatstack();
count++;
printf("enter a number");
scanf("%d",&temp->info);
temp->link = NULL;
if(start==NULL)
start = temp;
else
{
temp->link=start;
start=temp;
}
}
void pop()
{
struct stack *t;
int n;
n = start->info;
t = start->link;
free(start);
start = t;
count--;
printf("%d poped out successfully.\n", n);
}
void display()
{
struct stack *temp;
temp=start;
printf("There are %d element in stack \n",count);
while (temp->link != NULL)
{
printf("%d\n", temp->info);
temp = temp->link;
}
printf("%d\n", temp->info);
}
int main()
{
int x;
for(;;)
{
printf("\n1. for insert a element \n");
printf("2. for pop a element\n");
printf("3. for display\n");
printf("4. exit\n");
scanf("%d",&x);
if(x==1)
{
push();
}
else if(x==2)
pop();
else if(x==4)
break;
else if(x==3)
display();
else
printf("Enter a valid choice");
}
return 0;
}