-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q3.c
69 lines (69 loc) · 1.12 KB
/
Q3.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
#include<stdio.h>
#include<malloc.h>
struct node
{
int info;
struct node *next;
};
struct node *start = NULL,*last = NULL;
void insert()
{
struct node *q = (struct node*)malloc(sizeof(struct node));
printf("Enter Number: ");
scanf("%d",&q->info);
q->next = NULL;
if(start == NULL)
{
start = q;
last = q;
}
else
{
last->next = q;
last = q;
}
}
void display()
{
struct node *t = start;
if (start ==NULL)
{
printf("LL is empty!");
return;
}
while(t!=NULL)
{
printf("%d ",t->info);
t = t->next;
}
printf("\n");
}
void dellinkl()
{
struct node *t;
if(start==NULL)
{
printf("LL is already Empty!\n");
return;
}
while(start!=NULL)
{
t = start;
printf("%d Deleted\n",t->info);
start = t->next;
free(t);
}
}
void main()
{
dellinkl();
insert();
insert();
insert();
insert();
insert();
insert();
display();
dellinkl();
display();
}