|
<div class="cnblogs_code">
8
/6 10
/ /5 7 9 118
/10 6
/ /11 9 7 51.2.3.4.=root->->left=root->-right=->->
<div class="cnblogs_code">
= = __construct(->val = Mirror(&(== =->->left=->->right=->-><span style="color: #008000">//<span style="color: #008000">构造一个树
<span style="color: #800080">$node5=<span style="color: #0000ff">new TreeNode(5<span style="color: #000000">);
<span style="color: #800080">$node7=<span style="color: #0000ff">new TreeNode(7<span style="color: #000000">);
<span style="color: #800080">$node9=<span style="color: #0000ff">new TreeNode(9<span style="color: #000000">);
<span style="color: #800080">$node11=<span style="color: #0000ff">new TreeNode(11<span style="color: #000000">);
<span style="color: #800080">$node6=<span style="color: #0000ff">new TreeNode(6<span style="color: #000000">);
<span style="color: #800080">$node10=<span style="color: #0000ff">new TreeNode(10<span style="color: #000000">);
<span style="color: #800080">$node8=<span style="color: #0000ff">new TreeNode(8<span style="color: #000000">);
<span style="color: #800080">$node8->left=<span style="color: #800080">$node6<span style="color: #000000">;
<span style="color: #800080">$node8->right=<span style="color: #800080">$node10<span style="color: #000000">;
<span style="color: #800080">$node6->left=<span style="color: #800080">$node5<span style="color: #000000">;
<span style="color: #800080">$node6->right=<span style="color: #800080">$node7<span style="color: #000000">;
<span style="color: #800080">$node10->left=<span style="color: #800080">$node9<span style="color: #000000">;
<span style="color: #800080">$node10->right=<span style="color: #800080">$node11<span style="color: #000000">;
<span style="color: #800080">$tree=<span style="color: #800080">$node8<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">镜像这棵二叉树
<span style="color: #008080">var_dump(<span style="color: #800080">$tree<span style="color: #000000">);
Mirror(<span style="color: #800080">$tree<span style="color: #000000">);
<span style="color: #008080">var_dump(<span style="color: #800080">$tree);
<div class="cnblogs_code">
(TreeNode)
["val"]=>8"left"]=>
(TreeNode)
["val"]=>6"left"]=>
(TreeNode)
["val"]=>5"left"]=>
"right"]=>
"right"]=>
(TreeNode)
["val"]=>7"left"]=>
"right"]=>
"right"]=>
(TreeNode)
["val"]=>10"left"]=>
(TreeNode)
["val"]=>9"left"]=>
"right"]=>
"right"]=>
(TreeNode)
["val"]=>11"left"]=>
"right"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">7 (3) {
["val"]=><span style="color: #000000">
int(8<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">6 (3) {
["val"]=><span style="color: #000000">
int(10<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">4 (3) {
["val"]=><span style="color: #000000">
int(11<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
["right"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
}
["right"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">3 (3) {
["val"]=><span style="color: #000000">
int(9<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
["right"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
}
}
["right"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">5 (3) {
["val"]=><span style="color: #000000">
int(6<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">2 (3) {
["val"]=><span style="color: #000000">
int(7<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
["right"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
}
["right"]=>
<span style="color: #0000ff">object(TreeNode)<span style="color: #008000">#<span style="color: #008000">1 (3) {
["val"]=><span style="color: #000000">
int(5<span style="color: #000000">)
["left"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
["right"]=>
<span style="color: #0000ff">NULL<span style="color: #000000">
}
}
} (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|