⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.jad

📁 源程序(包括最初的版本
💻 JAD
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2005-6-30 13:20:16
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Tree.java

package App;

import java.io.PrintStream;
import queue.ArrayQueue;

// Referenced classes of package App:
//            TreeNode, Table, TableNode

public class Tree
{

    public Tree()
    {
    }

    public boolean isEmpty()
    {
        return root == null;
    }

    public Object root()
    {
        return root != null ? root.element : null;
    }

    public void makeTree(Object root, Object firstChild, Object nextSibling)
    {
        this.root = new TreeNode(root, ((Tree)firstChild).root, ((Tree)nextSibling).root);
    }

    public void creatTree(String s)
    {
        int i = 0;
        TreeNode r = root;
        ArrayQueue q = new ArrayQueue();
        String fa = s.substring(i, i + 1);
        for(String ch = s.substring(i + 1, i + 2); ch.compareTo("#") != 0; ch = s.substring(i + 1, i + 2))
        {
            TreeNode p1 = new TreeNode(ch);
            q.put(p1);
            if(fa.compareTo("#") == 0)
            {
                root = p1;
            } else
            {
                TreeNode p2;
                for(p2 = (TreeNode)q.getFrontElement(); !p2.element.equals(fa); p2 = (TreeNode)q.getFrontElement())
                    q.remove();

                if(p2.firstChild == null)
                {
                    p2.firstChild = p1;
                    r = p1;
                } else
                {
                    r.nextSibling = p1;
                    r = p1;
                }
            }
            i += 2;
            fa = s.substring(i, i + 1);
        }

    }

    public void init(String s)
    {
        creatTree(s);
        table = new Table();
        table.creatTable(s);
    }

    public void preOrder()
    {
        thePreOrder(root);
    }

    static void thePreOrder(TreeNode t)
    {
        if(t != null)
        {
            System.out.print(String.valueOf(String.valueOf(t.toString())).concat(" "));
            thePreOrder(t.firstChild);
            thePreOrder(t.nextSibling);
        }
    }

    public void postOrder()
    {
        thePostOrder(root);
    }

    static void thePostOrder(TreeNode t)
    {
        if(t != null)
        {
            thePostOrder(t.firstChild);
            System.out.print(String.valueOf(String.valueOf(t.toString())).concat(" "));
            thePostOrder(t.nextSibling);
        }
    }

    public static void main(String args[])
    {
        String s = "#AABACADBEBFCGDHDIDJ##";
        Tree t = new Tree();
        t.init(s);
        t.preOrder();
        System.out.println("\n");
        t.postOrder();
        System.out.println("\n");
        for(int i = 0; t.table.tables[i] != null; i++)
            System.out.println(t.table.tables[i].toString());

        System.out.println(t.table.number);
    }

    TreeNode root;
    Table table;
    String s;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -