#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<sstream>
using namespace std;
#define L 101
typedef struct node;
typedef node *tree; //tree => &node;tree本身就代表地址了
struct node{
int data;
tree left,right;
};
string s1= "DBEAC";
string s2= "ABCDE";
int m;
void noi(int n,int l,int h){
//cout << n << endl;
cout << s2[n];
m = s1.find(s2[n]);
if(m>l){ //有左子树
int x=s1.find(s2[n]);
//在s2中寻找符合要求的左子树的first,则为左子树节点(while取补集)
while((x>=m || x<l) &&(n<=s2.length()-1)) x=s1.find(s2[++n]);
//while(x>=m || x<l) x=s1.find(s2[++n]);
if(n<=s2.length()-1) noi(n,l,m-1); //罗生门
}
if(m<h){ //有右子树
int x=s1.find(s2[n]);
//while(x<=m || x<l) x=s1.find(s2[++n]);
while((x<=m || x<l) &&(n<=s2.length()-1)) x=s1.find(s2[++n]);
if(n<=s2.length()-1) noi(n,m+1,h);
}
}
int main()
{
noi(0,0,s2.length()-1);
return 0;
}
//cout << "输入:"
练习2 - 二叉树遍历
最新推荐文章于 2024-09-06 09:51:37 发布