Changeset 3e46075789 in tspsg for src/tspsolver.cpp
- Timestamp:
- Feb 17, 2010, 5:54:05 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 8203c075d5
- Parents:
- e4ae9e95f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tspsolver.cpp
re4ae9e95f7 r3e46075789 123 123 // Route with (nRow,nCol) path 124 124 right = new SStep(); 125 right->pNode = step; 125 126 right->matrix = step->matrix; 126 127 for (int k = 0; k < nCities; k++) { … … 137 138 // Route without (nRow,nCol) path 138 139 left = new SStep(); 140 left->pNode = step; 139 141 left->matrix = step->matrix; 140 142 left->matrix[nRow][nCol] = INFINITY; … … 183 185 { 184 186 if (root != NULL) 185 delete Node(root);187 deleteTree(root); 186 188 } 187 189 … … 215 217 mayNotBeOptimal = false; 216 218 if (root != NULL) 217 delete Node(root);219 deleteTree(root); 218 220 QApplication::restoreOverrideCursor(); 219 221 } 220 222 221 void CTSPSolver::deleteNode(SStep *&node) 222 { 223 //static int x; 224 // x++; 225 //qDebug() << ">>>" << x; 226 if (node->plNode != NULL) 227 deleteNode(node->plNode); 228 if (node->prNode != NULL) 229 deleteNode(node->prNode); 230 delete node; 231 node = NULL; 232 //qDebug() << "<<<" << x; 233 // x--; 223 void CTSPSolver::deleteTree(SStep *&root) 224 { 225 if (root == NULL) 226 return; 227 SStep *step = root; 228 SStep *parent; 229 forever { 230 if (step->plNode != NULL) { 231 // We have left child node - going inside it 232 step = step->plNode; 233 step->pNode->plNode = NULL; 234 continue; 235 } else if (step->prNode != NULL) { 236 // We have right child node - going inside it 237 step = step->prNode; 238 step->pNode->prNode = NULL; 239 continue; 240 } else { 241 // We have no child nodes. Deleting current one. 242 parent = step->pNode; 243 delete step; 244 if (parent != NULL) { 245 // Going back to the parent node. 246 step = parent; 247 } else { 248 // We came back to the root node. Finishing. 249 root = NULL; 250 break; 251 } 252 } 253 } 234 254 } 235 255
Note: See TracChangeset
for help on using the changeset viewer.