forked from keshavagarwal17/All-Cp-Algo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked list using two variables.c
71 lines (65 loc) · 1.3 KB
/
linked list using two variables.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
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int id;
int data;
struct node* next;
}a;
int main()
{
int i=1;
a *first=NULL,*t=NULL,*last=NULL,*temp=NULL;
for(;;)
{
int r;
printf("Do you want to enter data:(1-yes/0-no):");
scanf("%d",&r);
if(r==1)
{
t=(a*)malloc(sizeof(a));
t->id=i;
i++;
scanf("%d",&t->data);
t->next= NULL;
if(first==NULL)
{
first=t;
last=t;
}
else
{
last->next=t;
last=t;
}
}
else
break;
}
int p;
printf("Enter the id of data you want to delete:");
scanf("%d",&p);
t=first;
if(t->id==p)
{
temp=t;
first=t->next;
}
else
{
while(t->next->id!=p)
{
t=t->next;
}
temp=t->next;
t->next=temp->next;
free(temp);
}
t=first;
while(t!=NULL)
{
printf("%d\n",t->data);
t=t->next;
}
return 0;
}