前序满二叉树转化为后序满二叉树(递归)

/**
*2018.10.24 13:51
*前序满二叉树转化为后序满二叉树
*/
#include<stdio.h>

#define MAX 100


void preToPost(char [], int ,int ,char [], int ,int);

int main(void) {
	
	char pre[] = {'A','B','D','H','I','E','J','K','C' ,'F' ,'L','M','G','N','0' };
	char post[15];
	preToPost(pre,  0,  14,  post,  0,  14);

	for (int i = 0; i < 15; ++i) {
	
		printf("%c ", post[i]);
	
	}
	putchar('\n');
	system("pause");
	return 0;
}


void preToPost(char pre[], int s, int t, char post[], int ps, int pt) {
	if (s <= t) {
		post[pt] = pre[s];
		preToPost(pre, s + 1, (s + t)/2, post, ps, (ps + pt)/2 - 1);
		preToPost(pre, (s + t)/2 + 1, t, post, (ps + pt)/2 + 1, pt - 1);
	}
}
发布了48 篇原创文章 · 获赞 3 · 访问量 5140

猜你喜欢

转载自blog.csdn.net/ydeway/article/details/101039744