-
Notifications
You must be signed in to change notification settings - Fork 13
/
MergingLists.cpp
204 lines (173 loc) · 6.1 KB
/
MergingLists.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include<iostream>
#include<cstring>
using namespace std;
class List
{
public:
struct Node
{
int regNo;
char name[10];
float quizMarks;
Node *next;
};
Node *start;
void firstThingsFirst()
{
start=NULL;
}
void get()
{
int x=0;
while (x!=-1)
{
int regNo;
char name[10];
float quizMarks;
//cout<<"\n\nMenu:\n1. Input (head)\n2. Input (middle)\n3. Input (tail)\n4. Delete (head)\n5. Delete (middle)\n6. Delete (tail)\n7. Sort\n8. Exit\nX = ";
cout<<"\n\nMenu:\n1. Input (head)\n3. Input (tail)\n4. Delete (head)\n6. Delete (tail)\n7. Sort\n8. Exit\nX = ";
cin>>x;
switch (x)
{
case 1: cout<<"\tRegistration Number (int) = "; cin>>regNo;
cout<<"\tStudent Name (string) = "; cin>>name;
cout<<"\tQuiz Marks (float) = "; cin>>quizMarks;
fAdd(regNo,name,quizMarks);
break;
/*case 2: cout<<"\tInsert after = "; int p; cin>>p;
cout<<"\tRegistration Number (int) = "; cin>>regNo;
cout<<"\tStudent Name (string) = "; cin>>name;
cout<<"\tQuiz Marks (float) = "; cin>>quizMarks;
mAdd(p,regNo,name,quizMarks);
break;*/
case 3: cout<<"\tRegistration Number (int) = "; cin>>regNo;
cout<<"\tStudent Name (string) = "; cin>>name;
cout<<"\tQuiz Marks (float) = "; cin>>quizMarks;
bAdd(regNo,name,quizMarks);
break;
case 4: fDelete(); break;
/*case 5: cout<<"\tDelete after = "; cin>>p;
mDelete(p);
cout<<"\tTask complete.";
break;*/
case 6: bDelete(); break;
case 7: bubbleSort(); break;
default: cout<<"\n\nLIST SESSION TERMINATED.\n\n"; x=-1;
}
}
}
void fAdd(int rN,char n[10],float qM)
{
Node *obj=new Node;
obj->regNo=rN;
strcpy(obj->name,n);
obj->quizMarks=qM;
obj->next=NULL;
if (start==NULL) { start=obj; return; }
obj->next=start;
start=obj;
}
/*int mAdd(int rNADD,int rN,string n,float qM)
{
Node *obj=new Node,*temp;
obj->regNo=rN;
obj->name=n;
obj->quizMarks=qM;
obj->next=NULL;
if (start==NULL) start=obj;//0 nodes
else
{
temp=start;
while (temp->next!=NULL && (temp->next)->regNo!=rNADD) temp=temp->next;
obj->next=temp->next;
temp->next=obj;
}
delete obj;
delete temp;
return 0;
}*/
void bAdd(int rN,char n[10],float qM)
{
Node *obj=new Node,*temp;
obj->regNo=rN;
strcpy(obj->name,n);
obj->quizMarks=qM;
obj->next=NULL;
if (start==NULL) start=obj;//0 nodes
temp=start;
while (temp->next!=NULL) temp=temp->next;
temp->next=obj;
}
void fDelete()
{
if (start==NULL) { cout<<"[Y] delete complete"; return; }
start=start->next;
}
/*int mDelete(int rNDELETE)
{
Node *temp=start,*cache;
while (temp->next!=NULL && (temp->next)->regNo!=rNDELETE) temp=temp->next;
// < node@MAX
if (temp->next!=NULL)
{
cache=temp->next;
temp->next=(temp->next)->next;
}
delete temp;
delete cache;
return 0;
}*/
void bDelete()
{
Node *temp=start;
if (start==NULL) { cout<<"[X] underflow"; return; }//0 nodes
if (start->next==NULL) { start=NULL; return; }//1 node
while ((temp->next)->next!=NULL) temp=temp->next;
temp->next=NULL;
cout<<"[Y] delete complete";
}
void bubbleSort()
{
for (Node *i=start;i->next!=NULL;i=i->next)
for (Node *j=start;j->next!=NULL;j=j->next)
if (j->regNo>(j->next)->regNo)
{
int regNo=j->regNo;
char name[10]; strcpy(name,j->name);
float quizMarks=j->quizMarks;
j->regNo=(j->next)->regNo;
strcpy(j->name,(j->next)->name);
j->quizMarks=(j->next)->quizMarks;
(j->next)->regNo=regNo;
strcpy((j->next)->name,name);
(j->next)->quizMarks=quizMarks;
}
}
void link(List obj)
{
Node *temp=start;
while (temp->next!=NULL) temp=temp->next;
temp->next=obj.start;
cout<<"[Y] link complete";
}
void display()
{
cout<<"\n";
Node *temp=start;
while (temp!=NULL)
{
cout<<temp->regNo<<"\n";
temp=temp->next;
}
}
};
int main()
{
List l1,l2; l1.firstThingsFirst(); l2.firstThingsFirst();
cout<<"SET - A STUDENTS";
l1.get();
cout<<"SET - B STUDENTS";
l2.get();
l1.link(l2); l1.bubbleSort();
l1.display();
}