-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTermsList.cpp
More file actions
226 lines (195 loc) · 5.92 KB
/
Copy pathTermsList.cpp
File metadata and controls
226 lines (195 loc) · 5.92 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "TermsList.h"
#include "TermsBST.h"
#include "MemberQueue.h"
using namespace std;
TermsLIST::TermsLIST() : sizeList(0), head(nullptr)
{
}
TermsLIST::~TermsLIST()
{
}
TermsListNode* TermsLIST::getHead()
{
return head;
}
// insert
void TermsLIST::insert(MemberQueueNode* TLNode, TermsBST* TermsBST_A, TermsBST* TermsBST_B, TermsBST* TermsBST_C, TermsBST* TermsBST_D) {
//If there's nothing on the list
if (this->sizeList == 0) {
TermsListNode* newNode = new TermsListNode;
if (TLNode->gettype() == 'A') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_A->getRoot());
}
else if (TLNode->gettype() == 'B') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_B->getRoot());
}
else if (TLNode->gettype() == 'C') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_C->getRoot());
}
else {//If the last type of list is D
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_D->getRoot());
}
newNode->sizeup();
this->head = newNode;
this->sizeList++;
}
//When a node enters the TermsList for the second time
else if (this->sizeList == 1) {
TermsListNode* curNode;
curNode = this->head;
//Type duplication check
if (curNode->gettype() == TLNode->gettype()) {
curNode->sizeup();
}
else {//Connect a link-drip when the type of the new node is a type that was not in the TermsList
TermsListNode* newNode = new TermsListNode;
if (TLNode->gettype() == 'A') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_A->getRoot());
}
else if (TLNode->gettype() == 'B') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_B->getRoot());
}
else if (TLNode->gettype() == 'C') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_C->getRoot());
}
else { //If the last type of list is D
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_D->getRoot());
}
curNode->setNext(newNode);
newNode->setPrev(curNode);
newNode->sizeup();
this->sizeList++;
}
}
//When a node enters the TermsList for the third time
else if (this->sizeList == 2) {
TermsListNode* curNode;
curNode = this->head;
//Type duplication check
if (curNode->gettype() == TLNode->gettype()) {
curNode->sizeup();
}
//Type duplication check
else if ((curNode->getNext()->gettype()) == TLNode->gettype()) {
curNode->getNext()->sizeup();
}
else {//Connect a link-drip when the type of the new node is a type that was not in the TermsList
TermsListNode* newNode = new TermsListNode;
if (TLNode->gettype() == 'A') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_A->getRoot());
}
else if (TLNode->gettype() == 'B') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_B->getRoot());
}
else if (TLNode->gettype() == 'C') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_C->getRoot());
}
else { //If the last type of list is D
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_D->getRoot());
}
curNode->getNext()->setNext(newNode);
newNode->setPrev(curNode->getNext());
newNode->sizeup();
this->sizeList++; //increase list size
}
}
//When a node enters the TermsList for the fourth time
else {
TermsListNode* curNode;
curNode = this->head;
////Type duplication check
if (curNode->gettype() == TLNode->gettype()) {
curNode->sizeup();
}
//Type duplication check
else if ((curNode->getNext()->gettype()) == TLNode->gettype()) {
curNode->getNext()->sizeup();
}
//Type duplication check
else if ((curNode->getNext()->getNext()->gettype()) == (TLNode->gettype())) {
curNode->getNext()->getNext()->sizeup();
}
else { //If there is no overlap in any case and the fourth node is not on the list, determine it to be the last type
TermsListNode* newNode = new TermsListNode;
if (TLNode->gettype() == 'A') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_A->getRoot());
}
else if (TLNode->gettype() == 'B') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_B->getRoot());
}
else if (TLNode->gettype() == 'C') {
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_C->getRoot());
}
else { //If the last type of list is D
newNode->settype(TLNode->gettype());
newNode->setroot(TermsBST_D->getRoot());
}
curNode->getNext()->getNext()->setNext(newNode);
newNode->setNext(NULL);
newNode->setPrev(curNode->getNext()->getNext());
newNode->sizeup();
}
}
}
// delete
//Delete to match the location of the node you want to delete
void TermsLIST::delete_Termslist(TermsListNode* delNode) {
//When first erasing a node
if (delNode == this->head){
delNode->getNext()->setPrev(NULL);
this->head = delNode->getNext();
delNode->setNext(NULL);
delete delNode;
}
//When erasing the second or third node
else if ((delNode->getNext() != NULL)) {
delNode->getNext()->setPrev(delNode->getPrev());
delNode->getPrev()->setNext(delNode->getNext());
delNode->setNext(NULL);
delNode->setPrev(NULL);
}
//When erasing the last node
else {
delNode->getPrev()->setNext(NULL);
delNode->setPrev(NULL);
delete delNode;
}
}
//Delete LIST after updating size
void TermsLIST::size_update(TermsListNode* curNode, TermsBST* TermsBST_A, TermsBST* TermsBST_B, TermsBST* TermsBST_C, TermsBST* TermsBST_D) {
if (curNode->gettype() == 'A') {
curNode->setsize(TermsBST_A->getsize());
}
else if (curNode->gettype() == 'B') {
curNode->setsize(TermsBST_B->getsize());
}
else if (curNode->gettype() == 'C') {
curNode->setsize(TermsBST_C->getsize());
}
else if (curNode->gettype() == 'D') {
curNode->setsize(TermsBST_D->getsize());
}
curNode = this->head;
while (curNode != NULL) {
if (curNode->getsize_List() == 0) {
TermsListNode* delNode = curNode;
delete_Termslist(delNode);
}
curNode = curNode->getNext();
}
}