-
Notifications
You must be signed in to change notification settings - Fork 0
/
59.LinkedList_Concate.cpp
58 lines (51 loc) · 991 Bytes
/
59.LinkedList_Concate.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
#include<iostream>
using namespace std;
struct node{
int data;
node* next;
};
node* first = new node;
void create(node* p){
int num;
cout<<"enter number of elements in linked list: ";
cin>>num;
cout<<"enter "<<num<<" elements: ";
cin>>p->data;
for(int i=1;i<num;i++){
node* temp = new node;
cin>>temp->data;
temp->next = p->next;
p->next = temp;
p = temp;
}
}
void display(node* p){
cout<<endl;
while(p){
cout<<p->data<<" ";
p = p->next;
}
cout<<endl;
}
node* concatenate(node* &p, node* &q){
node* curr;
curr = p;
while(curr->next){
curr=curr->next;
}
curr->next = q;
q = nullptr;
return p;
}
int main(){
node* second = new node;;
create(first);
create(second);
cout<<"First: ";
display(first);
cout<<"Second: ";
display(second);
cout<<"Concatenating: ";
concatenate(first,second);
display(first);
}