#include<iostream>
#include<string>
using namespace std;
void preToPost(char pre[], int l1, int h1, char post[], int l2, int h2) {
int half;
if (l1 <= h1) {
post[h2] = pre[l1];
half = (h1 - l1) / 2;
preToPost(pre, l1 + 1, l1 + half, post, l2, l2 + half - 1);
preToPost(pre, l1 + half + 1, h1, post,l2 + half, h2 - 1);
}
}
int main() {
char pre[7] = { 'A','B','C','D','E','F','G' };
char post[7];
preToPost(pre, 0, 6, post, 0, 6);
int i;
for (i = 0; i < 7; i++) {
cout << post[i] << " ";
}
}
满二叉树,已知先序求后序
最新推荐文章于 2024-08-04 22:43:03 发布