可以跟之前这篇形成对比
http://blog.csdn.net/hhooong/article/details/43195395
代码如下:
#include<iostream> #include<string> using namespace std ; struct BinTreeNode { char data ; BinTreeNode *left ; BinTreeNode *right ; }; void BinTreeSuccess(char* post,char* in ,int length){ if(length == 0){ return ; } char value_node = post[length-1] ; int rootNum = 0 ; for(;rootNum <length;rootNum++){ if(in[rootNum] == value_node) break ; } cout <<value_node ; //cout <<rootNum ;// locate in the array; BinTreeSuccess(post,in,rootNum);//left_tree; BinTreeSuccess(post+rootNum,in+rootNum+1,length-rootNum-1);//right_tree; } int main (){ char* post = "DGEBHIFCA"; char* in ="DBGEACHFI"; int length = 9; BinTreeSuccess(post,in,length); return 0; }
贴个执行截图:看最下面的a.exe后输出的字符串
时间: 2024-10-03 05:01:37