-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinkedlist.c
More file actions
130 lines (100 loc) · 4.3 KB
/
Copy pathlinkedlist.c
File metadata and controls
130 lines (100 loc) · 4.3 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<stdio.h>
#include<stdlib.h>
struct list
{
int val;
struct list *next;
}node;
void main()
{
typedef struct list node;
int ch,data,pos,i,flg=-1;
node *c,*front,*rear,*d,*s,*t;
while(1)
{
printf("\n");
printf("\nCREATE=1");
printf("\nINSERT AT BEGINING=2");
printf("\nINSERT AT END=3");
printf("\nDISPLAY=4");
printf("\nINSERT AT DESIRES POSITION=5");
printf("\nDELETE FROM BEGINIG=6");
printf("\nDELETE AT END=7");
printf("\nDELETE AT A DESIRED POSITION=8");
printf("\n");
printf("\nWhat is your choice:\t");
scanf("%i",&ch);
switch(ch)
{
case 1 : c=(node*)malloc(sizeof(node));
front=(node*)malloc(sizeof(node));
rear=(node*)malloc(sizeof(node));
printf("\nEnter data:\t");
scanf("%i",&data);
c->val=data;
c->next=NULL;
front=c;
rear=c; flg++;
break;
case 2: c=(node*)malloc(sizeof(node));
printf("\nEnter data:\t");
scanf("%i",&data);
c->val=data;
c->next=front;
front=c;flg++;
break;
case 3 : c=(node*)malloc(sizeof(node));
printf("\nEnter data:\t");
scanf("%i",&data);
t=rear;
c->val=data;
rear->next=c;
c->next=NULL;
rear=c;flg++;break;
case 4: printf("\nThe linked list: \t");
d=front;
if(flg==-1)
{
printf("\nEmpty list");
}
else
{
while(d!=NULL)
{
printf("%i\t",d->val);
d=d->next;
}
}
break;
case 5: c=(node*)malloc(sizeof(node));
printf("\nEnter data:\t");
scanf("%i",&data);
printf("\nEnter the position:\t");
scanf("%i",&pos);
d=front;
c->val=data;
for(i=1;i<pos-1;i++)
d=d->next;
s=d->next;
d->next=c;
c->next=s;flg++;
break;
case 6 : d=front;
front=front->next;
free(d);
break;
case 7: free(t->next);
t->next=NULL;
break;
case 8: printf("\nEnter the position:\t");
scanf("%i",&pos);
d=front;
for(i=1;i<pos-1;i++)
d=d->next;
s=d->next;
d->next=s->next;
free(s);break;
case 9: exit(1);
}
}
}