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

📄 parenttree.java

📁 源程序(包括最初的版本
💻 JAVA
字号:
package tree;

/**
 *
 */
import queue.*;
class ParentTree {
    ParentTreeNode node[];
    int r,n;//根节点位置和节点个数

    public ParentTree() {
    }
    public ParentTree(ParentTreeNode node[],int r,int n){
        this.node=node;
        this.r=r;  this.n=n;
    }


    /** 由树的双亲表示法建立树的孩子兄弟链表*/
/*    public ChildSiblingNode makeChildSiblingTree(){
        ChildSiblingNode root=new ChildSiblingNode();
        theMakeChildSiblingTree(root);
        return root;
    }*/
    /**实际的由树的双亲表示法建立树的孩子兄弟链表算法*/
 /**   void theMakeChildSiblingTree(ChildSiblingNode t){
        ChildSiblingNode p1;
        ChildSiblingNode p2;
        ChildSiblingNode r=t;
        ArrayQueue q=new ArrayQueue();
        int i;
        for(i=0;i<n;i++) {
            p1=new ChildSiblingNode(node[i].element);
            q.put(p1);
            if(node[i].parent==-1) { t=p1; }
            else {
                p2=(ChildSiblingNode)q.getFrontElement();
                while(!p2.element.equals(node[node[i].parent].element)){
                    q.remove();
                    p2=(ChildSiblingNode)q.getFrontElement();
                }
                if(p2.firstChild==null) {
                    p2.firstChild=p1;  r=p1;//链接第一个孩子节点
                }
                else {
                    r.nextSibling=p1;r=p1;//链接其他孩子节点
                }
            }
        }
    }*/


    /**测试方法*/
    public static void main(String args[]) {
        ParentTreeNode a[]=new ParentTreeNode[7];
        a[0]=new ParentTreeNode("A",-1);
        a[1]=new ParentTreeNode("B",0);
        a[2]=new ParentTreeNode("C",0);
        a[3]=new ParentTreeNode("D",0);
        a[4]=new ParentTreeNode("E",2);
        a[5]=new ParentTreeNode("F",2);
        a[6]=new ParentTreeNode("G",5);
        ParentTree tree=new ParentTree(a,0,7);
        //tree.makeChildSiblingTree();
    }

}

⌨️ 快捷键说明

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