zoukankan      html  css  js  c++  java
  • 第十章 基本数据结构 练习 10.4-2

    package chap10;
    
    import static org.junit.Assert.*;
    
    import java.util.Stack;
    
    import org.junit.Test;
    
    public class exec10_4_2 {
        static void printTree(Tree tree) {
            Root root = tree.root;
            if (root != null) {
                Node node = root.node;
                System.out.println(node.key);
                printNode(node);
            }
        }
    
        /**
         * 递归实现
         * 
         * @param node
         */
        static void printNode(Node node) {
    
            if (node == null)
                return;
            else {
                Node left = node.left;
                Node right = node.right;
                printLeft(left);
                printLeft(right);
                printNode(left);
                printNode(right);
            }
    
        }
    
        static void printLeft(Node n) {
            if (n != null)
                System.out.println(n.key);
        }
    
        static void printRight(Node n) {
            if (n != null)
                System.out.println(n.key);
        }
    
        static Tree creatTree() {
            Tree t = new Tree();
            Root r = new Root();
            Node n1, n2, n3, n4, n5, n6, n7, n8, n9, n0;
            n1 = new Node(0);
            n2 = new Node(1);
            n3 = new Node(2);
            n4 = new Node(3);
            n5 = new Node(4);
            n6 = new Node(5);
            n7 = new Node(6);
            n8 = new Node(7);
            n9 = new Node(8);
            n0 = new Node(9);
            t.root = r;
            r.node = n0;
            n0.left = n1;
            n0.right = n2;
            n1.left = n3;
            n1.right = n4;
            n2.left = n5;
            n2.right = n6;
            n3.left = n7;
            n4.left = n8;
            n5.right = n9;
    
            return t;
        }
    
        @Test
        public void testName() throws Exception {
            Tree t1 = creatTree();
            printTree(t1);
        }
    }
  • 相关阅读:
    python迭代器与iter()函数实例教程
    手动安装python后,交互模式下退格键乱码
    find参数exec、管道符|、xargs的区别
    比较好的网址收集
    sed小知识总结
    irc操作小记
    irssi忽略退出,加入消息
    Web自动化简介
    android&ios区别
    移动自动化应用展望
  • 原文地址:https://www.cnblogs.com/xiaojintao/p/3782988.html
Copyright © 2011-2022 走看看