亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修改下面的代碼,在線等?

如何修改下面的代碼,在線等?

HUWWW 2019-03-13 14:15:52
我需要把下面這個有缺失的代碼實現,在這里,這個代碼的構造函數是不完整的,如何合理的完成構造函數的填充在完成構造函數部分之后,我需要在主函數中創建幾個節點, 然后使用findChild方法來找到每個節點的名字。怎么把findChild函數填充完整,這樣程序可以順利進行下面是代碼 package directory_explorer;import java.util.Map;import java.util.Collection;import java.util.HashMap;/** * The root of a tree representing a directory structure. */public class FileNode {    /** The name of the file or directory this node represents. */    private String name;    /** Whether this node represents a file or a directory. */    private FileType type;    /** This node's parent. */    private FileNode parent;    /**     * This node's children, mapped from the file names to the nodes. If type is     * FileType.FILE, this is null.     */    private Map<String, FileNode> children;    /**     * A node in this tree.     *     * @param name     *            the file     * @param parent     *            the parent node.     * @param type     *            file or directory     * @see buildFileTree     */    public FileNode(String name, FileNode parent, FileType type) {        this.name = name;        // TODO: complete this method.    }    /**     * Find and return a child node named name in this directory tree, or null     * if there is no such child node.     *     * @param name     *            the file name to search for     * @return the node named name     */    public FileNode findChild(String name) {        FileNode result = null;        // TODO: complete this method.        return result;    }    /**     * Return the name of the file or directory represented by this node.     *     * @return name of this Node     */    public String getName() {        return this.name;    }    /**     * Set the name of the current node     *     * @param name     *            of the file/directory     */    public void setName(String name) {        this.name = name;    }
查看完整描述

3 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

public FileNode findChild(String name){

    if(this.children!=null){

        if(name!=null){

            FileNode fileNode = null ;

            //此處每個節點 

            for (String key : children.keySet()) {

                if(key.equals(name)){

                    fileNode = children.get(key);

                }

            }

            return fileNode;

        }else{

            return null;

        }

        

    }else{

        return null;

    }

}


查看完整回答
反對 回復 2019-04-25
  • 3 回答
  • 0 關注
  • 533 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號