-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.c
76 lines (75 loc) · 1.34 KB
/
linked_list.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
70
71
72
73
74
75
76
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *link;
};
int main()
{
struct node *start;
start=NULL;
struct node *temp;
struct node *cur;
int i,num,ch;
do{
printf("\n\twelcome to operation on linked list\n");
printf("\n\t1.insertion\n\t2.delete a node\n\t3.display\n\t4.exit\n\tchoice:\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
temp=(struct node*)malloc(sizeof(struct node));
if(start==NULL)
{
printf("\nEnter the element to be inserted:\n");
scanf("%d",&num);
start=temp;
temp->data=num;
temp->link=NULL;
}
else
{
printf("\nEnter the element to be inserted:\n");
scanf("%d",&num);
temp->data=num;
temp->link=start;
start=temp;
}
break;
case 2:
if(start==NULL)
{
printf("\n\tlist is empty\n");
}
else if(start->link==NULL)
{
num=start->data;
start=NULL;
printf("\n\tdeleted element is %d:",num);
}
else
{
num=start->data;
start=start->link;
printf("\n\tdeleted element is %d:",num);
}
break;
case 3:
cur=start;
if(cur=NULL)
{
printf("\ngiven list is empty:");
}
else{
while(cur!=NULL)
{
printf("\n\t%d",start->data);
cur=cur->link;
}
}
break;
}
}while(ch<4);
return 0;
}