forked from s-u-m-i-t-0/stack.c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack
More file actions
91 lines (88 loc) · 1.65 KB
/
stack
File metadata and controls
91 lines (88 loc) · 1.65 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>
#include<conio.h>
#include<stdlib.h>
struct node{
int item;
struct node *next;
};
struct node* createNode()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
return(p);
}
void push(struct node **s)
{
struct node *n;
n=createNode();
printf("Enter the value:\n");
scanf("%d",&n->item);
n->next=NULL;
if(*s==NULL)
*s=n;
else{
n->next=*s;
*s=n;
}
}
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("%d ");
if(k==2)
{
printf("n");
}
}
}
void pop(struct node **s)
{
struct node *n;
if(*s== NULL)
printf("Linked list is Empty\n");
else{
n=*s;
*s=(*s)->next;
printf("Popped Element is (%d)\n",n->item);
free(n);
}
}
void display(struct node **s)
{
struct node *n;
if(*s== NULL)
printf("Linked list is Empty\n");
else{
n=*s;
while (n->next!=NULL)
{
printf("%d\t",n->item);
n=n->next;
}
printf("%d\n",n->item);
}
}
int main()
{
int x;
struct node *stack;
// stack=createNode();
stack=NULL;
while (1)
{
printf("\n1:PUSH\t2:POP\t3:DISPLAY\t4:EXIT\n");
scanf("%d",&x);
switch(x){
case 1:push(&stack);
break;
case 2:pop(&stack);
break;
case 3:display(&stack);
break;
case 4:exit(0);
break;
default:printf("Invalid chosise\n");
}
}
}