-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcatenationOf2LinkedLists.cpp
145 lines (131 loc) · 2.59 KB
/
ConcatenationOf2LinkedLists.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include<iostream>
using namespace std;
struct Student{
int id;
Student *next = NULL;
};
Student *first1 = NULL;
Student *last1 = NULL;
Student *first2 = NULL;
Student *last2 = NULL;
void displayLL1();
void insert_endLL1();
void displayLL2();
void insert_endLL2();
void mainMenu();
void displayConcatenate();
void concatenate2LL();
int main(){
mainMenu();
}
void mainMenu(){
cout<<"\nWhich task you want to perform"<<endl;
cout<<"1 - Insert At LL1 End \n";
cout<<"2 - Insert At LL2 End \n";
cout<<"3 - Display the LL1 \n";
cout<<"4 - Display the LL2 \n";
cout<<"5 - Merge Two \n";
cout<<"6 - Display the Merge \n";
cout<<"Enter Your Option: ";
int option;
cin>>option;
switch(option){
case 1:
insert_endLL1();
break;
case 2:
insert_endLL2();
break;
case 3:
displayLL1();
break;
case 4:
displayLL2();
break;
case 5:
concatenate2LL();
break;
case 6:
displayConcatenate();
break;
}
}
void insert_endLL1(){
cout<<"This is the function of insert_end LL1 \n";
Student *current = new Student;
cout<<"Enter ID: ";
cin>>current->id;
if (first1==NULL){
first1 = last1 = current;
}
else{
last1->next = current;
last1 = current;
}
mainMenu();
}
void insert_endLL2(){
cout<<"This is the function of insert_end LL2 \n";
Student *current = new Student;
cout<<"Enter ID: ";
cin>>current->id;
if (first2==NULL){
first2 = last2 = current;
}
else{
last2->next = current;
last2 = current;
}
mainMenu();
}
void displayLL1(){
cout<<"This is the function of display_The_LinkedList 1 \n";
Student *p = first1;
if (first1==NULL){
cout<<"Linked List Is Empty";
}else{
while(p!=NULL)
{
cout<<"ID: "<<p->id<<endl;
p = p->next;
}
}
mainMenu();
}
void displayLL2(){
cout<<"This is the function of display_The_LinkedList 1 \n";
Student *p = first2;
if (first2==NULL){
cout<<"Linked List Is Empty";
}else{
while(p!=NULL)
{
cout<<"ID: "<<p->id<<endl;
p = p->next;
}
}
mainMenu();
}
void concatenate2LL(){
cout<<"This is the function of Concatenation of 2 Linked Lists \n";
Student *p = first1;
while(p->next!=NULL){
p = p->next;
}
p->next = first2;
mainMenu();
}
void displayConcatenate(){
cout<<"This is the function of Displaying the concatenated 2 Linked Lists \n";
Student *p = first1;
if (first1==NULL){
cout<<"Linked List Is Empty";
}else{
while(p!=NULL)
{
cout<<"ID: "<<p->id<<endl;
p = p->next;
}
}
mainMenu();
}