-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab3(b)Q2.cpp
More file actions
78 lines (73 loc) · 1.37 KB
/
Lab3(b)Q2.cpp
File metadata and controls
78 lines (73 loc) · 1.37 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
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node*next;
Node*prev;
Node(int d){
data=d;
next=NULL;
prev=NULL;
}
};
Node*combining(Node*head1,Node*head2,Node*tail1,Node*tail2){
if(head1==NULL){
return head2;
}
if(head2==NULL){
return head1;
}
tail1->next=head2;
head2->prev=tail1;
tail2->next=head1;
head1->prev=tail2;
return head1;
}
void insertattail(Node*&head,Node*&tail,int v){
Node*temp=new Node(v);
if(head==NULL){
head=temp;
tail=temp;
temp->next = head;
head->prev = tail;
}else{
tail->next=temp;
temp->prev=tail;
tail=temp;
temp->next = head;
head->prev = tail;
}
}
void display(Node* head) {
if (head == NULL){
return ;
}
Node*temp=head;
do{
cout<<temp->data << "->";
temp = temp->next;
} while(temp!=head);
cout<<endl;
}
int main(){
Node*head=NULL;
Node*tail=NULL;
insertattail(head,tail,1);
insertattail(head,tail,7);
insertattail(head,tail,9);
insertattail(head,tail,2);
cout<<"LIST L"<<endl;
display(head);
Node*newhead=NULL;
Node*newtail=NULL;
insertattail(newhead,newtail,9);
insertattail(newhead,newtail,8);
insertattail(newhead,newtail,7);
insertattail(newhead,newtail,4);
cout<<"LIST M"<<endl;
display(newhead);
cout<<"COMBINED"<<endl;
Node*temp=combining(head,newhead,tail,newtail);
display(temp);
}