-
Notifications
You must be signed in to change notification settings - Fork 0
/
MRG.CPP
121 lines (95 loc) · 1.53 KB
/
MRG.CPP
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
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
class cll
{ struct node
{
int data;
node *next;
};
node *start;
node *last;
public:
void input();
void display();
void cir();
void merge();
cll()
{
node *start=NULL;
}
node* create()
{
node *nnd;
nnd=(node *)malloc(sizeof(node));
return nnd;
}
}obj,obj1;//class ends
void cll::merge()
{
obj.last->next=obj1.start;
cout<<"the merged list is \n"
node *ptr;
ptr=obj.start;
while(ptr!=NULL)
{
cout<<ptr->data;
ptr=ptr->next;
}
}
void cll:: input()
{
node *in; node *trav;
in =create();
last=in;
cout<<"enter the data ";
cin>>in->data;
in->next=NULL;
if(start==NULL)
{ start=in;
}
else
{
trav=start;
while(trav->next!=NULL)
{
trav=trav->next;
}
trav->next=in;
}
}
void cll:: display()
{
node *prnt;
prnt=start;
while(prnt->next!=NULL)
{
cout<<prnt->data;
prnt=prnt->next;
}
cout<<prnt->data<<endl;
}
void main()
{
int ele,ele1;
clrscr();
cout<<"enter the no of ele you want ";
cin>>ele;
for(int i=0;i<ele;i++)
{
obj.input();
}
cout<<endl;
obj.display();
cout<<"enter the no of element you want 2"<<endl;
cin>>ele1;
cout<<endl;
for(int j=0;j<ele1;j++)
{
obj1.input();
}
obj1.display();
cout<<endl;
obj.merge();
getch();
}