给出二叉数根节点,如何把这颗数在控制台以树形输出
C/C++ codeclass node{
public :
node* children[2];
string value;
}方法
void showTree(node* root){};
谁做过类似的的
()
C/C++ codeclass node{
public :
node* children[2];
string value;
}方法
void showTree(node* root){};
谁做过类似的的
()
调试欢乐多
void showTree(node* root,int n)
{
if(!root) return ;
if((null == root.chileren[0])&&(null == root.chileren[1])) return;
else
{
for(int i = 0;i < n; i++) printf("-");
printf("&d\n",root.value);
if(!root.chileren[0]) showTree(root.chileren[0],n++);
if(!root.chileren[1]) showTree(root.chileren[1],n++);
}
}
{
if(!root) return ;
if((null == root.chileren[0])&&(null == root.chileren[1])) return;
else
{
for(int i = 0;i < n; i++) printf("-");
printf("&d\n",root.value);
if(!root.chileren[0]) showTree(root.chileren[0],n + 1);
if(!root.chileren[1]) showTree(root.chileren[1],n + 1);
}
}