-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList_Stack.c
More file actions
84 lines (78 loc) · 1.47 KB
/
Copy pathLinkedList_Stack.c
File metadata and controls
84 lines (78 loc) · 1.47 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
#include <stdio.h>
#include <stdlib.h>
typedef struct node //Blueprint of single node
{
int data;
struct node *next;
} node_type;
typedef struct
{
node_type *top;
} STACK;
void push(node_type **top)
{
node_type *temp;
temp = (node_type *)malloc(sizeof(node_type));
if (temp == NULL)
printf("MEMORY FULL");
else
{
scanf("%d", &(temp->data));
temp->next = *top;
*top = temp;
}
}
void pop(node_type **top)
{
if (*top == NULL)
printf("LIST EMPTY");
else
{
node_type *temp = *top;
*top = (*top)->next;
printf("Poped element is : %d", temp->data);
free(temp);
}
}
void display(node_type **t)
{
node_type *top = *t;
if (top == NULL)
printf("LIST EMPTY");
else
{
while (top != NULL)
{
printf("%d\t", top->data);
top = top->next;
}
}
printf("\n");
}
int main()
{
STACK stack;
stack.top = NULL;
int run = 1;
while (run)
{
int ch;
printf("Enter the choice");
scanf("%d", &ch);
switch (ch)
{
case 1:
push(&(stack.top));
break;
case 2:
pop(&(stack.top));
break;
case 3:
display(&(stack.top));
break;
default:
run = 0;
}
}
return 0;
}