转载 AVL(平衡树)C++代码(非递归)

来源:互联网 发布:快期期货交易软件 编辑:程序博客网 时间:2024/06/05 20:13
  1. #define BALANCE_CHECK
  2. #ifndef NULL
  3. #define NULL 0
  4. #endif
  5. /*
  6.     Default Value Control
  7. */
  8. template<typename Type>
  9. struct DefaultValue
  10. {static Type Value;};
  11. template<typename Type>
  12. Type DefaultValue<Type>::Value;
  13. #define DECLARE_DEFAULT_VALUE(T, value) template<>/
  14. struct DefaultValue<T>{static T Value;};/
  15. template<>/
  16. T DefaultValue<T>::Value = value;
  17. DECLARE_DEFAULT_VALUE(int, 0)
  18. DECLARE_DEFAULT_VALUE(double, 0)
  19. /*
  20.     Node
  21.         if BALANCE_CHECK is defined, LHeight, RHeight and Height are used;
  22. */
  23. template<typename Type>
  24. struct Node
  25. {
  26.     Type    Data;
  27.     Node*   LChild, *RChild;
  28.     int     BalanceFactor;
  29.     
  30. #ifdef BALANCE_CHECK
  31. int     LHeight, RHeight, Height;
  32. #endif
  33.     
  34.     Node(const Type& _Data = DefaultValue<Type>::Value,
  35.         Node* _LChild = NULL,
  36.         Node* _RChild = NULL,
  37.         int   _BalanceFactor = 0):
  38.         Data(_Data), 
  39.         LChild(_LChild), 
  40.         RChild(_RChild),
  41.         BalanceFactor(_BalanceFactor)
  42.     {}
  43. };
  44. /*
  45.     AVLTree
  46.         if BALANCE_CHECK is defined, you can check the balance;
  47. */
  48. template<typename Type>
  49. class AVLTree
  50. {
  51. public:
  52.     
  53.         typedef Type              DataType;
  54.         typedef Node<Type>        NodeType;
  55.         typedef NodeType*         pNodeType;
  56.         typedef DefaultValue<Type> DefaultValueType;
  57.         
  58.         enum {LEFT, RIGHT};
  59.         
  60. public:
  61.     
  62.         AVLTree(): head(new NodeType) {}
  63.         ~AVLTree() {Destroy();}
  64.         
  65. public:
  66.     
  67.         int     Insert(const Type& it);
  68.         int     Delete(const Type& it);
  69.         int     GetMin(Type& it);
  70.         int      GetMax(Type& it);
  71. public:
  72.         
  73.         template<typename OP>
  74.         void    PreOrder(OP);
  75.         
  76.         template<typename OP>
  77.         void    InOrder(OP);
  78.         
  79.     template<typename OP>
  80.         void    PreInOrder(int type, OP);
  81.         
  82. private:
  83.         inline  void        ReplaceChild(pNodeType  Parent, pNodeType Child, pNodeType NewChild);
  84.         
  85.         inline  void        RRotateFactorI(pNodeType Parent, pNodeType Tree);
  86.         inline  void        RRotateFactorD(pNodeType Parent, pNodeType Tree);
  87.         inline  pNodeType   RRotate(pNodeType Parent, pNodeType Tree);
  88.         
  89.         inline  void        LRRotateFactorI(pNodeType Parent, pNodeType Tree);
  90.         inline  void        LRRotateFactorD(pNodeType Parent, pNodeType Tree);
  91.         inline  pNodeType   LRRotate(pNodeType Parent, pNodeType Tree);
  92.         
  93.         inline  void        LRotateFactorI(pNodeType Parent, pNodeType Tree);
  94.         inline  void        LRotateFactorD(pNodeType Parent, pNodeType Tree);
  95.         inline  pNodeType   LRotate(pNodeType Parent, pNodeType Tree);
  96.         
  97.         
  98.         inline  void        RLRotateFactorI(pNodeType Parent, pNodeType Tree);
  99.         inline  void        RLRotateFactorD(pNodeType Parent, pNodeType Tree);
  100.         inline  pNodeType   RLRotate(pNodeType Parent, pNodeType Tree);
  101.         
  102.         void                Destroy();
  103.         void                Destroy(pNodeType Tree);
  104. private:
  105.         NodeType* head; 
  106.         
  107.         
  108. #ifdef BALANCE_CHECK
  109. public:
  110.         int     BalanceCheck();
  111.         int     BalanceCheck(pNodeType tree);
  112. #endif
  113. };
  114. template<typename Type>
  115. int AVLTree<Type>::Insert(const Type& it)
  116. {
  117.     pNodeType Parent = head, Curr = head->LChild;
  118.     pNodeType LastNotBalance = NULL, ParentLastNotBalance = NULL;
  119.     
  120.     while (Curr)
  121.     {
  122.         if (Curr->Data == it) return 0;
  123.         if (Curr->BalanceFactor) 
  124.             ParentLastNotBalance = Parent, LastNotBalance = Curr;
  125.         Parent = Curr;
  126.         Curr = it < Curr->Data ? Curr->LChild : Curr->RChild;
  127.     }
  128.     
  129.     pNodeType NewNode = new NodeType(it);
  130.     
  131.     if (Parent == head)
  132.     {
  133.         head->LChild = NewNode;
  134.         return 1;
  135.     }
  136.     else
  137.     {
  138.         it < Parent->Data ? 
  139.             Parent->LChild = NewNode :
  140.             Parent->RChild = NewNode;
  141.     }
  142.     
  143.     for (Curr = LastNotBalance ? LastNotBalance : head->LChild;
  144.         Curr != NewNode;)
  145.     {
  146.         it < Curr->Data ?
  147.             (++Curr->BalanceFactor, Curr = Curr->LChild):
  148.             (--Curr->BalanceFactor, Curr = Curr->RChild);
  149.     }
  150.     
  151.     if (!LastNotBalance || LastNotBalance->BalanceFactor < 2 &
  152.             LastNotBalance->BalanceFactor > -2)
  153.         return 1;
  154.     
  155.     if (it < LastNotBalance->Data)
  156.     {
  157.         if (it < LastNotBalance->LChild->Data )
  158.         {
  159.             RRotateFactorI(ParentLastNotBalance, LastNotBalance);
  160.             ReplaceChild(
  161.                         ParentLastNotBalance, 
  162.                         LastNotBalance,
  163.                         RRotate(ParentLastNotBalance, LastNotBalance)
  164.                         );
  165.         }
  166.         else
  167.         {
  168.             LRRotateFactorI(ParentLastNotBalance, LastNotBalance);      
  169.             ReplaceChild(
  170.                         ParentLastNotBalance, 
  171.                         LastNotBalance,
  172.                         LRRotate(ParentLastNotBalance, LastNotBalance)
  173.                         );
  174.         }
  175.     }
  176.     else
  177.     {
  178.         if (it > LastNotBalance->RChild->Data)
  179.         {
  180.             LRotateFactorI(ParentLastNotBalance, LastNotBalance);
  181.             ReplaceChild(
  182.                         ParentLastNotBalance, 
  183.                         LastNotBalance,
  184.                         LRotate(ParentLastNotBalance, LastNotBalance)
  185.                         );
  186.         }
  187.         else
  188.         {
  189.             
  190.             RLRotateFactorI(ParentLastNotBalance, LastNotBalance);
  191.             ReplaceChild(
  192.                         ParentLastNotBalance, 
  193.                         LastNotBalance,
  194.                         RLRotate(ParentLastNotBalance, LastNotBalance)
  195.                         );
  196.         }
  197.     }
  198.     return 1;
  199. }
  200. template<typename Type>
  201. int AVLTree<Type>::Delete(const Type& it)
  202. {
  203.     pNodeType SearchHistory[64];
  204.     int       SearchDirection[64];
  205.     int       CurrIdx;
  206.     
  207.     pNodeType Curr = head->LChild;
  208.     SearchHistory[0] = head;
  209.     SearchDirection[0] = 0;
  210.     CurrIdx = 1;
  211.     
  212.     while (Curr && Curr->Data != it)
  213.     {
  214.         SearchHistory[CurrIdx] = Curr;
  215.         it < Curr->Data ?
  216.             (Curr = Curr->LChild, SearchDirection[CurrIdx] = LEFT): 
  217.             (Curr = Curr->RChild, SearchDirection[CurrIdx] = RIGHT);
  218.         ++CurrIdx;
  219.     }
  220.     
  221.     if (!Curr) return 0;
  222.     
  223.     pNodeType ToBeDeleted = Curr;
  224.     if (Curr->LChild && Curr->RChild)
  225.     {
  226.         pNodeType  CurrT = Curr->LChild;
  227.         SearchHistory[CurrIdx] = Curr;
  228.         SearchDirection[CurrIdx++] = LEFT;
  229.         while (CurrT->RChild)
  230.         {
  231.             SearchHistory[CurrIdx] = CurrT;
  232.             SearchDirection[CurrIdx++] = RIGHT;
  233.             CurrT = CurrT->RChild;
  234.         }
  235.         Curr->Data = CurrT->Data;
  236.         ToBeDeleted = CurrT;
  237.     }
  238.     
  239.     
  240.     // There exists at least one child that is NULL
  241.     {
  242.         pNodeType Temp = 
  243.             ToBeDeleted->LChild ?
  244.                 ToBeDeleted->LChild :
  245.                     (ToBeDeleted->RChild  ? ToBeDeleted->RChild : NULL);
  246.         delete ToBeDeleted;
  247.         --CurrIdx;//    Indidate the pointer to the parent of the node to be deleted
  248.         SearchDirection[CurrIdx] == RIGHT ?
  249.             SearchHistory[CurrIdx]->RChild = Temp:
  250.             SearchHistory[CurrIdx]->LChild = Temp;
  251.     }
  252.     for (int HeightChanged = 1; HeightChanged && CurrIdx; --CurrIdx)
  253.     {   
  254.         pNodeType ToBeAdjusted = SearchHistory[CurrIdx];
  255.         pNodeType ParentToBeAdjusted = SearchHistory[CurrIdx-1];
  256.         int       ChangedChild = SearchDirection[CurrIdx];
  257.         if (ToBeAdjusted->BalanceFactor == 0)
  258.         {
  259.             ToBeAdjusted->BalanceFactor = ChangedChild == LEFT? -1 : 1;
  260.             HeightChanged = 0;
  261.         }
  262.         else if (ToBeAdjusted->BalanceFactor == -1)
  263.         {
  264.             if (ChangedChild == RIGHT)
  265.             {
  266.                 ToBeAdjusted->BalanceFactor = 0;
  267.                 HeightChanged = 1;
  268.             }
  269.             else
  270.             {
  271.                 switch (ToBeAdjusted->RChild->BalanceFactor)
  272.                 {
  273.                 case 0:
  274.                     HeightChanged = 0;
  275.                     LRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  276.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  277.                                 LRotate(ParentToBeAdjusted, ToBeAdjusted));
  278.                     break;
  279.                 case -1:
  280.                     HeightChanged = 1;
  281.                     LRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  282.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  283.                                 LRotate(ParentToBeAdjusted, ToBeAdjusted));
  284.                     break;
  285.                 case 1:
  286.                     HeightChanged = 1;
  287.                     RLRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  288.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  289.                                 RLRotate(ParentToBeAdjusted, ToBeAdjusted));
  290.                 }
  291.             }
  292.         }
  293.         else
  294.         {
  295.             if (ChangedChild == LEFT)
  296.             {
  297.                 ToBeAdjusted->BalanceFactor = 0;
  298.                 HeightChanged = 1;
  299.             }
  300.             else
  301.             {
  302.                 switch (ToBeAdjusted->LChild->BalanceFactor)
  303.                 {
  304.                 case 0:
  305.                     HeightChanged = 0;
  306.                     RRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  307.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  308.                                 RRotate(ParentToBeAdjusted, ToBeAdjusted));
  309.                     break;
  310.                 case 1:
  311.                     HeightChanged = 1;
  312.                     RRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  313.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  314.                                 RRotate(ParentToBeAdjusted, ToBeAdjusted));
  315.                     break;
  316.                 case -1:
  317.                     HeightChanged = 1;
  318.                     LRRotateFactorD(ParentToBeAdjusted, ToBeAdjusted);
  319.                     ReplaceChild(ParentToBeAdjusted, ToBeAdjusted,
  320.                                 LRRotate(ParentToBeAdjusted, ToBeAdjusted));
  321.                 }
  322.             }
  323.         }       
  324.     }
  325.     
  326.     return 1;
  327. }
  328. template<typename Type>
  329. int     AVLTree<Type>::GetMin(Type& it)
  330. {
  331.     pNodeType   Curr = head->LChild;
  332.     if (!Curr) return 0;
  333.     while (Curr->LChild) Curr = Curr->LChild;
  334.     it = Curr->Data;
  335.     return 1;
  336. }   
  337. template<typename Type>
  338. int     AVLTree<Type>::GetMax(Type& it)
  339. {
  340.     pNodeType   Curr = head->LChild;
  341.     if (!Curr) return 0;
  342.     while (Curr->RChild) Curr = Curr->RChild;
  343.     it = Curr->Data;
  344.     return 1;
  345. }    
  346. template<typename Type>
  347. template<typename OP>
  348. void AVLTree<Type>::PreOrder(OP ope)
  349. {
  350.     PreInOrder(0, ope);
  351. }
  352. template<typename Type>
  353. template<typename OP>
  354. void AVLTree<Type>::InOrder(OP ope)
  355. {
  356.     PreInOrder(1, ope);
  357. }
  358. template<typename Type>
  359. template<typename OP>
  360. void AVLTree<Type>::PreInOrder(int type, OP ope)
  361. {
  362.     pNodeType Curr = head->LChild;
  363.     pNodeType R = NULL;
  364.     
  365.     while (true)
  366.     {
  367.         if (Curr == NULL) break;
  368.         
  369.         pNodeType q = Curr->LChild;
  370.         if (q == NULL)
  371.         {
  372.             ope(Curr->Data);
  373.             R = Curr;
  374.             Curr = Curr->RChild;
  375.         }
  376.         else
  377.         {
  378.             while (q->RChild != NULL && q->RChild != Curr)
  379.                 q = q->RChild;
  380.             if (q->RChild == NULL)
  381.             {
  382.                 q->RChild = Curr;
  383.                 if (type == 0) ope(Curr->Data);;
  384.                 Curr = Curr->LChild;
  385.             }
  386.             else
  387.             {   
  388.                 R = Curr;
  389.                 if (type == 1) ope(Curr->Data);
  390.                 Curr = Curr->RChild;
  391.                 q->RChild = NULL;
  392.             }
  393.             
  394.         }
  395.     }
  396. }
  397. template<typename Type>
  398. inline  void        
  399. AVLTree<Type>::ReplaceChild(pNodeType  Parent, pNodeType Child, pNodeType NewChild)
  400. {
  401.     Parent->LChild == Child ?
  402.         Parent->LChild = NewChild :
  403.         Parent->RChild = NewChild ;
  404. }
  405. // Right rotate the tree
  406. template<typename Type>
  407. inline void 
  408. AVLTree<Type>::RRotateFactorI(pNodeType Parent, pNodeType Tree)
  409. {
  410.     Tree->BalanceFactor = 0;
  411.     Tree->LChild->BalanceFactor = 0;
  412. }
  413. template<typename Type>
  414. inline void
  415. AVLTree<Type>::RRotateFactorD(pNodeType Parent, pNodeType Tree)
  416. {
  417.     pNodeType A = Tree;
  418.     pNodeType B = Tree->LChild;
  419.     if (B->BalanceFactor == 0)
  420.     {
  421.         A->BalanceFactor = 1;
  422.         B->BalanceFactor = -1;
  423.     }
  424.     else
  425.     {
  426.         A->BalanceFactor = 0;
  427.         B->BalanceFactor = 0;
  428.     }
  429. }
  430. template<typename Type>
  431. inline typename AVLTree<Type>::pNodeType 
  432. AVLTree<Type>::RRotate(pNodeType Parent, pNodeType Tree)
  433. {
  434.     pNodeType A = Tree;
  435.     pNodeType B = Tree->LChild;
  436.     A->LChild = B->RChild;
  437.     B->RChild = A;
  438.     return B;
  439. }
  440. // Left rotate the LChild of the tree and right rotate the tree
  441. template<typename Type>
  442. inline void
  443. AVLTree<Type>::LRRotateFactorI(pNodeType Parent, pNodeType Tree)
  444. {
  445.     pNodeType A = Tree;
  446.     pNodeType B = Tree->LChild;
  447.     pNodeType C = B->RChild;
  448.     
  449.     switch (C->BalanceFactor)
  450.     {
  451.     case  1:
  452.                 B->BalanceFactor = 0;
  453.                 A->BalanceFactor = -1;
  454.                 C->BalanceFactor = 0;
  455.                 break;
  456.     case -1:
  457.                 B->BalanceFactor = 1;
  458.                 A->BalanceFactor = 0;
  459.                 C->BalanceFactor = 0;
  460.                 break;
  461.     case 0:
  462.                 B->BalanceFactor = 0;
  463.                 A->BalanceFactor = 0;
  464.                 C->BalanceFactor = 0;
  465.     }
  466. }
  467. template<typename Type>
  468. inline void
  469. AVLTree<Type>::LRRotateFactorD(pNodeType Parent, pNodeType Tree)
  470. {
  471.     pNodeType A = Tree;
  472.     pNodeType B = Tree->LChild;
  473.     pNodeType C = B->RChild;
  474.     
  475.     switch (C->BalanceFactor)
  476.     {
  477.     case  -1:
  478.                 A->BalanceFactor = 0;
  479.                 B->BalanceFactor = 1;
  480.                 C->BalanceFactor = 0;
  481.                 break;
  482.     case 0:
  483.                 A->BalanceFactor = 0;
  484.                 B->BalanceFactor = 0;
  485.                 C->BalanceFactor = 0;
  486.                 break;
  487.     case 1:
  488.                 A->BalanceFactor = -1;
  489.                 B->BalanceFactor = 0;
  490.                 C->BalanceFactor = 0;
  491.     }
  492. }
  493. template<typename Type>
  494. inline typename AVLTree<Type>::pNodeType
  495. AVLTree<Type>::LRRotate(pNodeType Parent, pNodeType Tree)
  496. {
  497.     pNodeType A = Tree;
  498.     pNodeType B = Tree->LChild;
  499.     pNodeType C = B->RChild;
  500.     
  501.     B->RChild = C->LChild;
  502.     A->LChild = C->RChild;
  503.     C->LChild = B;
  504.     C->RChild = A;
  505.                 
  506.     return C;
  507. }
  508. // Left rotate the tree
  509. template<typename Type>
  510. inline void
  511. AVLTree<Type>::LRotateFactorI(pNodeType Parent, pNodeType Tree)
  512. {
  513.     Tree->BalanceFactor = 0;
  514.     Tree->RChild->BalanceFactor = 0;
  515. }
  516. template<typename Type>
  517. inline void
  518. AVLTree<Type>::LRotateFactorD(pNodeType Parent, pNodeType Tree)
  519. {
  520.     pNodeType A = Tree;
  521.     pNodeType B = Tree->RChild;
  522.     if (B->BalanceFactor == 0)
  523.     {
  524.         A->BalanceFactor = -1;
  525.         B->BalanceFactor = 1;
  526.     }
  527.     else
  528.     {
  529.         A->BalanceFactor = 0;
  530.         B->BalanceFactor = 0;
  531.     }
  532. }
  533. template<typename Type>
  534. inline typename AVLTree<Type>::pNodeType
  535. AVLTree<Type>::LRotate(pNodeType Parent, pNodeType Tree)
  536. {
  537.     pNodeType A = Tree;
  538.     pNodeType B = Tree->RChild;
  539.     
  540.     A->RChild = B->LChild;
  541.     B->LChild = A;
  542.     
  543.     return B;
  544. }
  545. // Right rotate the RChild of the tree and left rotate the tree
  546. template<typename Type>
  547. inline void
  548. AVLTree<Type>::RLRotateFactorI(pNodeType Parent, pNodeType Tree)
  549. {
  550.     pNodeType A = Tree;
  551.     pNodeType B = Tree->RChild;
  552.     pNodeType C = B->LChild;
  553.     
  554.     switch (C->BalanceFactor)
  555.     {
  556.     case  1:
  557.             B->BalanceFactor = -1;
  558.             A->BalanceFactor = 0;
  559.             C->BalanceFactor = 0;
  560.             break;
  561.     case -1:
  562.             B->BalanceFactor = 0;
  563.             A->BalanceFactor = 1;
  564.             C->BalanceFactor = 0;
  565.             break;
  566.     case 0:
  567.             B->BalanceFactor = 0;
  568.             A->BalanceFactor = 0;
  569.             C->BalanceFactor = 0;
  570.     }
  571. }
  572. template<typename Type>
  573. inline void
  574. AVLTree<Type>::RLRotateFactorD(pNodeType Parent, pNodeType Tree)
  575. {
  576.     
  577.     pNodeType A = Tree;
  578.     pNodeType B = Tree->RChild;
  579.     pNodeType C = B->LChild;
  580.     
  581.     switch (C->BalanceFactor)
  582.     {
  583.     case  -1:
  584.                 A->BalanceFactor = 1;
  585.                 B->BalanceFactor = 0;
  586.                 C->BalanceFactor = 0;
  587.                 break;
  588.     case 0:
  589.                 A->BalanceFactor = 0;
  590.                 B->BalanceFactor = 0;
  591.                 C->BalanceFactor = 0;
  592.                 break;
  593.     case 1:
  594.                 A->BalanceFactor = 0;
  595.                 B->BalanceFactor = -1;
  596.                 C->BalanceFactor = 0;
  597.     }
  598. }
  599. template<typename Type>
  600. inline typename AVLTree<Type>::pNodeType
  601. AVLTree<Type>::RLRotate(pNodeType Parent, pNodeType Tree)
  602. {
  603.     pNodeType A = Tree;
  604.     pNodeType B = Tree->RChild;
  605.     pNodeType C = B->LChild;
  606.             
  607.     B->LChild = C->RChild;
  608.     A->RChild = C->LChild;
  609.     C->LChild = A;
  610.     C->RChild = B;
  611.             
  612.     return C;
  613. }
  614. template<typename Type>
  615. void    AVLTree<Type>::Destroy()
  616. {
  617.     if (head) Destroy(head->LChild);
  618.     head = NULL;
  619. }    
  620. template<typename Type>
  621. void    AVLTree<Type>::Destroy(pNodeType Tree)
  622. {
  623.     if (!Tree) return;
  624.     Destroy(Tree->LChild);
  625.     Destroy(Tree->RChild);
  626.     delete Tree;
  627. }
  628. #ifdef BALANCE_CHECK
  629. template<typename Type>
  630. int AVLTree<Type>::BalanceCheck()
  631. {
  632.     return BalanceCheck(head->LChild);
  633. }
  634. template<typename Type>
  635. int AVLTree<Type>::BalanceCheck(pNodeType tree)
  636. {
  637.     int LBalance = 1, RBalance = 1;
  638.     if (tree->LChild)
  639.     {   
  640.         LBalance = BalanceCheck(tree->LChild);
  641.         tree->LHeight = tree->LChild->Height;
  642.     }
  643.     else
  644.     {
  645.         tree->LHeight = 0;
  646.     }
  647.     if (tree->RChild)
  648.     {   
  649.         RBalance = BalanceCheck(tree->RChild);
  650.         tree->RHeight = tree->RChild->Height;
  651.     }
  652.     else
  653.     {
  654.         tree->RHeight = 0;
  655.     }
  656.     
  657.     tree->Height = max(tree->LHeight, tree->RHeight) + 1;
  658.     return LBalance && RBalance &
  659.         tree->BalanceFactor == tree->LHeight - tree->RHeight;
  660. }
  661. #endif
  662. #include <iostream>
  663. #include <cstdlib>
  664. #include <ctime>
  665. using namespace std;
  666. template<typename T>
  667. void visit(T i)
  668. {cout << i << " ";}    
  669. int main()
  670. {
  671.     AVLTree<int> it;
  672.     int m;
  673.     
  674.     it.Insert(1);
  675.     for (int i = 0; i < 24; ++i)
  676.         it.Insert(rand());
  677.     it.InOrder(visit<int>);
  678.     it.GetMax(m);
  679.     cout << endl << m << endl;
  680.     it.GetMin(m);
  681.     cout << m << endl;
  682.     system("pause");
  683.     return 0;
  684. }
  685. 转自 http://blog.csdn.net/baihacker/archive/2008/08/20/2803362.aspx
原创粉丝点击