forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack implement with linked lis
More file actions
75 lines (67 loc) · 1.36 KB
/
stack implement with linked lis
File metadata and controls
75 lines (67 loc) · 1.36 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
#include<stdio.h>
#include<malloc.h>
#define max 15
typedef struct node
{ int data,*next;
}node;
int main()
{ int ch,choic,x;
node *p,*top;
top=NULL;
printf("\n\n1-push,\n2-pop,\n3=display:");
do
{
printf("enter the choics::\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
p=(node*)malloc(sizeof(node));
printf("\nenter the element=");
scanf("%d",&p->data);
if (top==NULL)
{
top=p;
top->next=NULL;
}
else{
p->next=top;
top=p;
}
break;
case 2:
p=(node*)malloc(sizeof(node));
if (top==NULL)
{
printf("stack is empty");
}
else{
x=top->data;
top=p;
printf("%d is poped from stack:",x);
top=top->next;
free(p);
}
break;
case 3:
p=(node*)malloc(sizeof(node));
if (top==NULL)
{
printf("\nstack is empty");
}
else{
p=top;
while (p!=NULL)
{
printf("%d\t",p->data);
p=p->next;
}
} break;
default:
printf("enter the correct choice::");
}
printf("\n if you want to repeat. prees 1\n");
scanf("%d",&choic);
} while (choic==1);
return 0;
}