-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlinked_list_CONCAT.c
More file actions
82 lines (72 loc) · 1.67 KB
/
Copy pathlinked_list_CONCAT.c
File metadata and controls
82 lines (72 loc) · 1.67 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
#include<stdio.h>
#include<stdlib.h>
typedef struct list
{
int data;
struct list* link;
}node;
node* concat(node* list1,node* list2)
{
if(list1==NULL)
return list2;
if(list2==NULL)
return list1;
node* temp=list1;
while(temp->link!=NULL)
temp=temp->link;
temp->link=list2;
return list1;
}
int main()
{
node* first_1=(node*)malloc(sizeof(node));
node* first_2=(node*)malloc(sizeof(node));
first_1->data=99;
first_1->link=NULL;
first_2->data=100;
first_2->link=NULL;
node *second_1=NULL; //node 2
second_1=(node*)malloc(sizeof(node));
second_1->data=77;
second_1->link=NULL;
node *second_2=NULL; //node 2
second_2=(node*)malloc(sizeof(node));
second_2->data=77;
second_2->link=NULL;
first_1->link=second_1;
first_2->link=second_2;
node *third_1=NULL; //node 3
third_1=(node*)malloc(sizeof(node));
third_1->data=88;
third_1->link=NULL;
node *third_2=NULL; //node 3
third_2=(node*)malloc(sizeof(node));
third_2->data=88;
third_2->link=NULL;
second_1->link=third_1;
second_2->link=third_2;
node* temp=first_1;
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->link;
}
printf("\n");
free(temp);
temp=first_2;
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->link;
}
printf("\n");
free(temp);
first_1=concat(first_1, first_2);
temp=first_1;
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->link;
}
printf("\n");
}