如何深度复制二叉树?

如何深度复制二叉树?,第1张

如何深度复制二叉树?

尝试

class Node {    private String value;    private Node left;    private Node right;    public Node(String value, Node left, Node right) {        this.value = value;        ...    }    Node copy() {        Node left = null;        Node right = null;        if (this.left != null) { left = this.left.copy();        }        if (this.right != null) { right = this.right.copy();        }        return new Node(value, left, right);    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5586638.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存