-
Notifications
You must be signed in to change notification settings - Fork 0
/
Append_DS.txt
93 lines (75 loc) · 1.38 KB
/
Append_DS.txt
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
#include<stdio.h>
#include<malloc.h>
typedef struct list
{
int data;
struct list *next;
} list;
void insert_end(list **head,int value)
{
list *node=(list *)malloc(sizeof(list));
node->data=value;
node->next=NULL;
list *p;
if(*head==NULL)
{
*head=node;
}
else
{
p= *head;
while(p->next !=NULL)
{
p=p->next;
}
p->next=node;
}
}
void print(list *head)
{
if(head==NULL)
{
printf("list is empty\n");
}
else
{
while(head !=NULL)
{
printf("%d -> ",head->data);
head=head->next;
}
printf("NULL\n");
}
}
int main()
{
list *head1=NULL;
list *head2=NULL;
int i,n,value;
printf("Enter number for list 1: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&value);
insert_end(&head1,value);
}
print(head1);
printf("\n");
printf("Enter number for list 2 : ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&value);
insert_end(&head2,value);
}
print(head2);
list *p=head2;
while(p !=NULL)
{
insert_end(&head1,p->data);
p=p->next;
}
printf("\n\n");
print(head1);
return 0;
}