forked from PankajJadwal/DS_B
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackUsingLL.c
More file actions
78 lines (76 loc) · 1.26 KB
/
Copy pathStackUsingLL.c
File metadata and controls
78 lines (76 loc) · 1.26 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
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
} node;
node *init(int x)
{
node *temp = (node *)malloc(sizeof(node));
temp->data = x;
temp->next = NULL;
return temp;
}
node *push(node *head, int x)
{
node *temp = init(x);
if (head == NULL)
{
return temp;
}
temp->next=head;
return temp;
}
void display(node *head)
{
if(head==NULL)
{
printf("Stack is empty\n");
return;
}
node *c = head;
while (c)
{
printf("%d ", c->data);
c = c->next;
}
printf("\n");
}
node *pop(node *head)
{
if(head->next==NULL)
{
return NULL;
}
if (head == NULL)
{
printf("Underflow\n");
return NULL;
}
node *temp = head;
head=head->next;
free(temp);
return head;
}
int main()
{
node *head = NULL;
// node* head=init(10);
head = push(head, 10);
display(head);
head = push(head, 20);
display(head);
head = push(head, 30);
display(head);
head = push(head, 40);
display(head);
head = pop(head);
display(head);
head = pop(head);
display(head);
head = pop(head);
display(head);
head = pop(head);
display(head);
}