zoukankan      html  css  js  c++  java
  • 打印树


      利用了树的中序遍历,不过是从右边到左边的中序遍历。
    #include <iostream.h>
    #include 
    "tree.h"

    template
    <class NODETYPE>
    void outputTree(TreeNode<NODETYPE> *ptr,int totalSpaces)
    {
        
    if(ptr!=0)
        
    {
            outputTree(ptr
    ->rightPtr,totalSpaces+5);
            
    for(int i=0;i<totalSpaces;i++)
                cout
    <<' ';
            cout
    <<ptr->getData()<<endl;
            outputTree(ptr
    ->leftPtr,totalSpaces+5);

        }

    }



    int main()
    {

         Tree<int> intTree;
         
    int intVal;

        cout
    <<"Enter 15 integer valuse\n";
        
    for(int i=0;i<15;i++)
        
    {
            cin
    >>intVal;
            intTree.insertNode(intVal);
        }


        outputTree(intTree.rootPtr,
    0);

        
    return 0;
    }
                 
    运行结果:
                  99
              97
                   92
         83
                   72
              71
                   69
    49
                   44
              40
                   32
         28
                   19
              18
                   11
  • 相关阅读:
    Codeforces 837F Prefix Sums
    Codeforces 822E Liar dp + SA (看题解)
    Codeforces 989D A Shade of Moonlight
    Codeforces 887D Ratings and Reality Shows
    Codeforces 666E E
    Codeforces 436E Cardboard Box (看题解)
    Codeforces 342D Xenia and Dominoes 状压dp
    js倒计时
    $.extends 继承原理
    js点击回到顶部2
  • 原文地址:https://www.cnblogs.com/junnyfeng/p/192929.html
Copyright © 2011-2022 走看看