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
  • 相关阅读:
    Keras实例教程(2)
    Keras实例教程(1)
    tf.nn.l2_loss()的用法
    在tensorflow中使用batch normalization
    Tensorflow的LRN是怎么做的
    CNN卷积中多通道卷积的参数问题
    caffe学习网站
    交叉熵反向求导计算过程
    矩阵求导
    循环神经网络(RNN)模型与前向反向传播算法
  • 原文地址:https://www.cnblogs.com/junnyfeng/p/192929.html
Copyright © 2011-2022 走看看