00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <string>
00042
00043 #include <qgarlib/QgarErrorUser.H>
00044
00045
00046
00047 namespace qgar
00048 {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 template <class T>
00066 GenTreeNode<T>::GenTreeNode()
00067
00068 : _pParent(0),
00069 _pLSibling(0),
00070 _pRSibling(0),
00071 _pFirstChild(0),
00072 _data()
00073
00074 {
00075
00076 }
00077
00078
00079
00080
00081 template <class T>
00082 GenTreeNode<T>::GenTreeNode(const T& aData)
00083
00084 : _pParent(0),
00085 _pLSibling(0),
00086 _pRSibling(0),
00087 _pFirstChild(0),
00088 _data(aData)
00089
00090 {
00091
00092 }
00093
00094
00095
00096
00097 template <class T>
00098 GenTreeNode<T>::GenTreeNode(GenTreeNode<T>* aPParent,
00099 GenTreeNode<T>* aPLSibling,
00100 GenTreeNode<T>* aPRSibling,
00101 GenTreeNode<T>* aPFirstChild,
00102 const T& aData)
00103
00104 : _pParent(aPParent),
00105 _pLSibling(aPLSibling),
00106 _pRSibling(aPRSibling),
00107 _pFirstChild(aPFirstChild),
00108 _data(aData)
00109
00110 {
00111
00112 }
00113
00114
00115 template <class T>
00116 GenTreeNode<T>::GenTreeNode(const GenTreeNode<T>& aNode)
00117 : _pParent(aNode._pParent),
00118 _pLSibling(aNode._pLSibling),
00119 _pRSibling(aNode._pRSibling),
00120 _pFirstChild(aNode._pFirstChild),
00121 _data(aNode._data)
00122 {
00123
00124 }
00125
00126
00127
00128
00129
00130
00131
00132 template <class T>
00133 GenTreeNode<T>::~GenTreeNode()
00134 {
00135
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 template <class T>
00147 inline GenTreeNode<T>* GenTreeNode<T>::pParent() const
00148 {
00149 return _pParent;
00150 }
00151
00152
00153
00154
00155 template <class T>
00156 inline GenTreeNode<T>* GenTreeNode<T>::pLSibling() const
00157 {
00158 return _pLSibling;
00159 }
00160
00161
00162
00163
00164 template <class T>
00165 inline GenTreeNode<T>* GenTreeNode<T>::pRSibling() const
00166 {
00167 return _pRSibling;
00168 }
00169
00170
00171
00172
00173 template <class T>
00174 inline GenTreeNode<T>* GenTreeNode<T>::pFirstChild() const
00175 {
00176 return _pFirstChild;
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 template <class T>
00188 inline void GenTreeNode<T>::setPParent(GenTreeNode<T>* aPNode)
00189 {
00190 _pParent = aPNode;
00191 }
00192
00193
00194
00195
00196 template <class T>
00197 inline void GenTreeNode<T>::setPLSibling(GenTreeNode<T>* aPNode)
00198 {
00199 _pLSibling = aPNode;
00200 }
00201
00202
00203
00204
00205 template <class T>
00206 inline void GenTreeNode<T>::setPRSibling(GenTreeNode<T>* aPNode)
00207 {
00208 _pRSibling = aPNode;
00209 }
00210
00211
00212
00213
00214 template <class T>
00215 inline void GenTreeNode<T>::setPFirstChild(GenTreeNode<T>* aPNode)
00216 {
00217 _pFirstChild = aPNode;
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 template <class T>
00229 inline const T& GenTreeNode<T>::accessData() const
00230 {
00231 return _data;
00232 }
00233
00234
00235
00236
00237 template <class T>
00238 inline T GenTreeNode<T>::data() const
00239 {
00240 return _data;
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 template <class T>
00252 inline void GenTreeNode<T>::setData(const T& aData)
00253 {
00254 _data = aData;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 template <class T>
00266 GenTreeNode<T>& GenTreeNode<T>::operator=(const GenTreeNode<T>& aNode)
00267 {
00268
00269 if (this != &aNode)
00270 {
00271 _pParent = aNode.pParent();
00272 _pLSibling = aNode.pLSibling();
00273 _pRSibling = aNode.pRSibling();
00274 _pFirstChild = aNode.pFirstChild();
00275 _data = aNode.data();
00276 }
00277
00278 return *this;
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 template <class T>
00305 GenTree<T>::GenTree()
00306
00307 : _pRoot(0),
00308 _pCurrent(0)
00309
00310 {
00311
00312 }
00313
00314
00315
00316
00317 template <class T>
00318 GenTree<T>::GenTree(const T& aData)
00319
00320 : _pRoot(new GenTreeNode<T>(aData))
00321
00322 {
00323 _pCurrent = _pRoot;
00324 }
00325
00326
00327
00328
00329
00330 template <class T>
00331 GenTree<T>::GenTree(const GenTree<T>& aTree)
00332
00333 : _pRoot(PRIVATEdeepCopy(aTree._pRoot))
00334
00335 {
00336 _pCurrent = _pRoot;
00337 }
00338
00339
00340
00341
00342
00343 template <class T>
00344 GenTree<T>::GenTree(GenTreeNode<T>* aPNode)
00345 {
00346 if (aPNode == 0)
00347 {
00348
00349 _pRoot = 0;
00350 _pCurrent = 0;
00351 }
00352 else
00353 {
00354
00355
00356 GenTreeNode<T>* proot =
00357 new GenTreeNode<T>(0,
00358 0,
00359 0,
00360 aPNode->pFirstChild(),
00361 aPNode->data());
00362
00363
00364 _pRoot = PRIVATEdeepCopy(proot);
00365 _pCurrent = _pRoot;
00366
00367
00368 proot->setPFirstChild(0);
00369 delete proot;
00370 }
00371 }
00372
00373
00374
00375
00376
00377
00378
00379 template <class T>
00380 GenTree<T>::~GenTree()
00381 {
00382 PRIVATEdelete(_pRoot);
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 template <class T>
00394 bool GenTree<T>::empty() const
00395 {
00396 return _pRoot == 0;
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 template <class T>
00408 inline GenTreeNode<T>*
00409 GenTree<T>::pRoot() const
00410 {
00411 return _pRoot;
00412 }
00413
00414
00415
00416
00417 template <class T>
00418 inline GenTreeNode<T>*
00419 GenTree<T>::pCurrent() const
00420 {
00421 return _pCurrent;
00422 }
00423
00424
00425
00426
00427 template <class T>
00428 inline GenTreeNode<T>*
00429 GenTree<T>::pParent() const
00430 {
00431 return _pCurrent->pParent();
00432 }
00433
00434
00435
00436
00437 template <class T>
00438 inline GenTreeNode<T>*
00439 GenTree<T>::pParent(GenTreeNode<T>* aPNode) const
00440 {
00441 return aPNode->pParent();
00442 }
00443
00444
00445
00446
00447 template <class T>
00448 inline GenTreeNode<T>*
00449 GenTree<T>::pLSibling() const
00450 {
00451 return _pCurrent->pLSibling();
00452 }
00453
00454
00455
00456
00457 template <class T>
00458 inline GenTreeNode<T>*
00459 GenTree<T>::pLSibling(GenTreeNode<T>* aPNode) const
00460 {
00461 return aPNode->pLSibling();
00462 }
00463
00464
00465
00466
00467 template <class T>
00468 inline GenTreeNode<T>*
00469 GenTree<T>::pRSibling() const
00470 {
00471 return _pCurrent->pRSibling();
00472 }
00473
00474
00475
00476
00477 template <class T>
00478 inline GenTreeNode<T>*
00479 GenTree<T>::pRSibling(GenTreeNode<T>* aPNode) const
00480 {
00481 return aPNode->pRSibling();
00482 }
00483
00484
00485
00486
00487 template <class T>
00488 inline GenTreeNode<T>*
00489 GenTree<T>::pFirstChild() const
00490 {
00491 return _pCurrent->pFirstChild();
00492 }
00493
00494
00495
00496
00497 template <class T>
00498 inline GenTreeNode<T>*
00499 GenTree<T>::pFirstChild(GenTreeNode<T>* aPNode) const
00500 {
00501 return aPNode->pFirstChild();
00502 }
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 template <class T>
00513 inline const T&
00514 GenTree<T>::accessData() const
00515 {
00516 return _pCurrent->accessData();
00517 }
00518
00519
00520
00521
00522 template <class T>
00523 inline const T&
00524 GenTree<T>::accessData(GenTreeNode<T>* aPNode) const
00525 {
00526 return aPNode->accessData();
00527 }
00528
00529
00530
00531
00532 template <class T>
00533 inline T
00534 GenTree<T>::data() const
00535 {
00536 return _pCurrent->data();
00537 }
00538
00539
00540
00541
00542 template <class T>
00543 inline T
00544 GenTree<T>::data(GenTreeNode<T>* aPNode) const
00545 {
00546 return aPNode->data();
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 template <class T>
00558 inline void
00559 GenTree<T>::gotoRoot()
00560 {
00561 _pCurrent = _pRoot;
00562 }
00563
00564
00565
00566
00567 template <class T>
00568 inline void
00569 GenTree<T>::gotoParent()
00570 {
00571 _pCurrent = _pCurrent->pParent();
00572 }
00573
00574
00575
00576
00577 template <class T>
00578 inline void
00579 GenTree<T>::gotoParent(GenTreeNode<T>* aPNode)
00580 {
00581 _pCurrent = aPNode->pParent();
00582 }
00583
00584
00585
00586 template <class T>
00587 inline void
00588 GenTree<T>::gotoLSibling()
00589 {
00590 _pCurrent = _pCurrent->pLSibling();
00591 }
00592
00593
00594
00595
00596 template <class T>
00597 inline void
00598 GenTree<T>::gotoLSibling(GenTreeNode<T>* aPNode)
00599 {
00600 _pCurrent = aPNode->pLSibling();
00601 }
00602
00603
00604
00605
00606 template <class T>
00607 inline void
00608 GenTree<T>::gotoRSibling()
00609 {
00610 _pCurrent = _pCurrent->pRSibling();
00611 }
00612
00613
00614
00615
00616 template <class T>
00617 inline void
00618 GenTree<T>::gotoRSibling(GenTreeNode<T>* aPNode)
00619 {
00620 _pCurrent = aPNode->pRSibling();
00621 }
00622
00623
00624
00625
00626 template <class T>
00627 inline void
00628 GenTree<T>::gotoFirstChild()
00629 {
00630 _pCurrent = _pCurrent->pFirstChild();
00631 }
00632
00633
00634
00635
00636 template <class T>
00637 inline void
00638 GenTree<T>::gotoFirstChild(GenTreeNode<T>* aPNode)
00639 {
00640 _pCurrent = aPNode->pFirstChild();
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651 template <class T>
00652 inline void
00653 GenTree<T>::setData(const T& aData)
00654 {
00655 _pCurrent->setData(aData);
00656 }
00657
00658
00659
00660
00661 template <class T>
00662 inline void
00663 GenTree<T>::setData(const T& aData, GenTreeNode<T>* aPNode)
00664 {
00665 aPNode->setData(aData);
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 template <class T>
00686 void
00687 GenTree<T>::insertParent(const T& aData)
00688 {
00689 if (empty())
00690 {
00691
00692 _pRoot = new GenTreeNode<T>(aData);
00693 _pCurrent = _pRoot;
00694 }
00695 else
00696 {
00697
00698
00699 _pRoot->setPParent(new GenTreeNode<T>(0,
00700 0,
00701 0,
00702 _pRoot,
00703 aData));
00704
00705 _pRoot = _pRoot->pParent();
00706 }
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 template <class T>
00724 void
00725 GenTree<T>::insertLSibling(const T& aData)
00726
00727 throw(QgarErrorUser)
00728
00729 {
00730 if (empty())
00731 {
00732
00733 _pRoot = new GenTreeNode<T>(aData);
00734 _pCurrent = _pRoot;
00735 }
00736 else if (_pCurrent->pParent() == 0)
00737 {
00738
00739 throw QgarErrorUser(__FILE__, __LINE__,
00740 "template <class T> void qgar::GenTree<T>::insertLSibling(const T&)",
00741 "A root of a tree cannot be provided with left siblings");
00742 }
00743 else
00744 {
00745
00746 GenTreeNode<T>* pNew
00747 = new GenTreeNode<T>(_pCurrent->pParent(),
00748 _pCurrent->pLSibling(),
00749 _pCurrent,
00750 0,
00751 aData);
00752
00753
00754 if (_pCurrent->pLSibling() == 0)
00755 {
00756
00757 ( _pCurrent->pParent() )->setPFirstChild(pNew);
00758 }
00759 else
00760 {
00761
00762 ( _pCurrent->pLSibling() )->setPRSibling(pNew);
00763 }
00764
00765
00766 _pCurrent->setPLSibling(pNew);
00767 }
00768 }
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784 template <class T>
00785 inline void
00786 GenTree<T>::insertLSibling(const T& aData, GenTreeNode<T>* aPNode)
00787
00788 throw(QgarErrorUser)
00789
00790 {
00791 _pCurrent = aPNode;
00792 insertLSibling(aData);
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 template <class T>
00810 void
00811 GenTree<T>::insertRSibling(const T& aData)
00812
00813 throw(QgarErrorUser)
00814
00815 {
00816 if (empty())
00817 {
00818
00819 _pRoot = new GenTreeNode<T>(aData);
00820 _pCurrent = _pRoot;
00821 }
00822 else if (_pCurrent->pParent() == 0)
00823 {
00824
00825 throw QgarErrorUser(__FILE__, __LINE__,
00826 "template <class T> void qgar::GenTree<T>::insertRSibling(const T&)",
00827 "A root of a tree cannot be provided with right siblings");
00828 }
00829 else
00830 {
00831
00832 GenTreeNode<T>* pNew
00833 = new GenTreeNode<T>(_pCurrent->pParent(),
00834 _pCurrent,
00835 _pCurrent->pRSibling(),
00836 0,
00837 aData);
00838
00839
00840 if (_pCurrent->pRSibling() != 0)
00841 {
00842
00843 ( _pCurrent->pRSibling() )->setPLSibling(pNew);
00844 }
00845
00846
00847 _pCurrent->setPRSibling(pNew);
00848 }
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865 template <class T>
00866 inline void
00867 GenTree<T>::insertRSibling(const T& aData, GenTreeNode<T>* aPNode)
00868
00869 throw(QgarErrorUser)
00870
00871 {
00872 _pCurrent = aPNode;
00873 insertRSibling(aData);
00874 }
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890 template <class T>
00891 void
00892 GenTree<T>::insertFirstChild(const T& aData)
00893 {
00894 if (empty())
00895 {
00896
00897 _pRoot = new GenTreeNode<T>(aData);
00898 _pCurrent = _pRoot;
00899 }
00900 else
00901 {
00902
00903 GenTreeNode<T>* pNew
00904 = new GenTreeNode<T>(_pCurrent,
00905 0,
00906 _pCurrent->pFirstChild(),
00907 0,
00908 aData);
00909
00910
00911 GenTreeNode<T>* pfc = _pCurrent->pFirstChild();
00912 if (pfc != 0)
00913 {
00914 pfc->setPLSibling(pNew);
00915 }
00916
00917
00918 _pCurrent->setPFirstChild(pNew);
00919 }
00920 }
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936 template <class T>
00937 inline void
00938 GenTree<T>::insertFirstChild(const T& aData, GenTreeNode<T>* aPNode)
00939 {
00940 _pCurrent = aPNode;
00941 insertFirstChild(aData);
00942 }
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969 template <class T>
00970 void
00971 GenTree<T>::mergeLSibling(const GenTree<T>& aTree)
00972
00973 throw(QgarErrorUser)
00974
00975 {
00976
00977 if (aTree.empty())
00978 {
00979 return;
00980 }
00981
00982 if (empty())
00983 {
00984
00985 _pRoot = PRIVATEdeepCopy(aTree.pRoot());
00986 _pCurrent = _pRoot;
00987 }
00988 else
00989 {
00990
00991
00992 if (_pCurrent == _pRoot)
00993 {
00994
00995 throw QgarErrorUser(__FILE__, __LINE__,
00996 "template <class T> void qgar::GenTree<T>::mergeLSibling(const qgar::GenTree<T>&)",
00997 "A root of a tree cannot be provided with left siblings");
00998 }
00999
01000
01001 GenTreeNode<T>* pRootCopy = PRIVATEdeepCopy(aTree.pRoot());
01002
01003 pRootCopy->setPParent(_pCurrent->pParent());
01004 pRootCopy->setPLSibling(_pCurrent->pLSibling());
01005 pRootCopy->setPRSibling(_pCurrent);
01006
01007
01008 if (_pCurrent->pLSibling() == 0)
01009 {
01010
01011
01012 (_pCurrent->pParent())->setPFirstChild(pRootCopy);
01013 }
01014 else
01015 {
01016
01017
01018 (_pCurrent->pLSibling())->setPRSibling(pRootCopy);
01019 }
01020
01021
01022 _pCurrent->setPLSibling(pRootCopy);
01023 }
01024 }
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046 template <class T>
01047 void
01048 GenTree<T>::mergeLSibling(const GenTree<T>& aTree,
01049 GenTreeNode<T>* aPNode)
01050
01051 throw(QgarErrorUser)
01052
01053 {
01054 _pCurrent = aPNode;
01055 mergeLSibling(aTree);
01056 }
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078 template <class T>
01079 void
01080 GenTree<T>::mergeRSibling(const GenTree<T>& aTree)
01081
01082 throw(QgarErrorUser)
01083
01084 {
01085
01086 if (aTree.empty())
01087 {
01088 return;
01089 }
01090
01091 if (empty())
01092 {
01093
01094 _pRoot = PRIVATEdeepCopy(aTree.pRoot());
01095 _pCurrent = _pRoot;
01096 }
01097 else
01098 {
01099
01100
01101 if (_pCurrent == _pRoot)
01102 {
01103
01104 throw QgarErrorUser(__FILE__, __LINE__,
01105 "template <class T> void qgar::GenTree<T>::mergeRSibling(const qgar::GenTree<T>&)",
01106 "A root of a tree cannot be provided with right siblings");
01107 }
01108
01109
01110 GenTreeNode<T>* pRootCopy = PRIVATEdeepCopy(aTree.pRoot());
01111
01112 pRootCopy->setPParent(_pCurrent->pParent());
01113 pRootCopy->setPLSibling(_pCurrent);
01114 pRootCopy->setPRSibling(_pCurrent->pRSibling());
01115
01116
01117 if (_pCurrent->pRSibling() != 0)
01118 {
01119
01120 (_pCurrent->pRSibling())->setPLSibling(pRootCopy);
01121 }
01122
01123
01124 _pCurrent->setPRSibling(pRootCopy);
01125 }
01126 }
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148 template <class T>
01149 void
01150 GenTree<T>::mergeRSibling(const GenTree<T>& aTree,
01151 GenTreeNode<T>* aPNode)
01152
01153 throw(QgarErrorUser)
01154
01155 {
01156 _pCurrent = aPNode;
01157 mergeRSibling(aTree);
01158 }
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180 template <class T>
01181 void
01182 GenTree<T>::mergeFirstChild(const GenTree<T>& aTree)
01183 {
01184
01185 if (aTree.empty())
01186 {
01187 return;
01188 }
01189
01190
01191 GenTreeNode<T>* pRootCopy = PRIVATEdeepCopy(aTree.pRoot());
01192
01193 if (empty())
01194 {
01195
01196 _pRoot = pRootCopy;
01197 _pCurrent = _pRoot;
01198 }
01199 else
01200 {
01201
01202
01203
01204 if (pRootCopy != 0)
01205 {
01206 pRootCopy->setPParent(_pCurrent);
01207 pRootCopy->setPLSibling(0);
01208 pRootCopy->setPRSibling(_pCurrent->pFirstChild());
01209 }
01210
01211
01212 if (_pCurrent->pFirstChild() != 0)
01213 {
01214
01215 (_pCurrent->pFirstChild())->setPLSibling(pRootCopy);
01216 }
01217
01218
01219 _pCurrent->setPFirstChild(pRootCopy);
01220 }
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244 template <class T>
01245 void
01246 GenTree<T>::mergeFirstChild(const GenTree<T>& aTree,
01247 GenTreeNode<T>* aPNode)
01248 {
01249 _pCurrent = aPNode;
01250 mergeFirstChild(aTree);
01251 }
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 template <class T>
01273 GenTreeNode<T>*
01274 GenTree<T>::remove()
01275 {
01276 if (empty())
01277 {
01278
01279 return _pRoot;
01280 }
01281
01282 if (_pCurrent == _pRoot)
01283 {
01284
01285
01286
01287 GenTreeNode<T>* p = _pCurrent;
01288 _pRoot = 0;
01289 _pCurrent = 0;
01290
01291 return p;
01292 }
01293
01294
01295 GenTreeNode<T>* pp = _pCurrent->pParent();
01296 GenTreeNode<T>* prs = _pCurrent->pRSibling();
01297 GenTreeNode<T>* pls = _pCurrent->pLSibling();
01298
01299
01300 if (prs != 0)
01301 {
01302 prs->setPLSibling(pls);
01303 }
01304
01305
01306 if (pls == 0)
01307 {
01308
01309 pp->setPFirstChild(prs);
01310 }
01311 else
01312 {
01313
01314 pls->setPRSibling(prs);
01315 }
01316
01317
01318 GenTreeNode<T>* p = _pCurrent;
01319 _pCurrent = _pRoot;
01320
01321 return p;
01322 }
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338 template <class T>
01339 GenTreeNode<T>*
01340 GenTree<T>::remove(GenTreeNode<T>* aPNode)
01341 {
01342 if (aPNode == _pCurrent)
01343 {
01344 return remove();
01345 }
01346 else
01347 {
01348 GenTreeNode<T>* pSaveCurr = _pCurrent;
01349 _pCurrent = aPNode;
01350 remove();
01351 _pCurrent = pSaveCurr;
01352 return aPNode;
01353 }
01354 }
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365 template <class T>
01366 GenTree<T>&
01367 GenTree<T>::operator=(const GenTree<T>& aTree)
01368 {
01369
01370 if (this != &aTree)
01371 {
01372 _pRoot = PRIVATEdeepCopy(aTree._pRoot);
01373 _pCurrent = _pRoot;
01374 }
01375
01376 return *this;
01377 }
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388 template <class T>
01389 GenTreeNode<T>*
01390 GenTree<T>::PRIVATEdeepCopy(GenTreeNode<T>* aPNode,
01391 GenTreeNode<T>* aPFCopy,
01392 GenTreeNode<T>* aPLSCopy)
01393 const
01394
01395 {
01396 if (aPNode == 0)
01397 {
01398
01399 return aPNode;
01400 }
01401 else
01402 {
01403
01404 GenTreeNode<T>* copy = new GenTreeNode<T>(aPNode->data());
01405
01406
01407 copy->setPParent(aPFCopy);
01408 copy->setPLSibling(aPLSCopy);
01409
01410
01411 copy->setPFirstChild(PRIVATEdeepCopy(aPNode->pFirstChild(), copy, 0));
01412
01413
01414 copy->setPRSibling(PRIVATEdeepCopy(aPNode->pRSibling(),
01415 aPFCopy,
01416 copy));
01417
01418
01419 return copy;
01420 }
01421 }
01422
01423
01424
01425
01426 template <class T>
01427 void
01428 GenTree<T>::PRIVATEdelete(GenTreeNode<T>* aPNode)
01429 {
01430 if (aPNode != 0)
01431 {
01432
01433 PRIVATEdelete(aPNode->pFirstChild());
01434
01435 PRIVATEdelete(aPNode->pRSibling());
01436
01437
01438 delete aPNode;
01439 }
01440 }
01441
01442
01443
01444
01445
01446
01447
01448 }