钢琴怎么自学
////中序遍历: ADEFGHMZ 前序遍历:GDAFEMHZ 输出结果 AEFDHZMG
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
超轻粘土手工制作图片大全
#include <string>
#include <iomanip>
#define MAX 100
using namespace std;
struct TreeNode
{
struct TreeNode* left;
struct TreeNode* right;
char elem;
};
void BinaryTreeFromOrderings(char* inorder, char* preorder, int length)
{
if(length == 0)手机屏幕大小
{
//cout<<"invalid length";
return;
}
TreeNode* node = new TreeNode;//Noice that [new] should be written out.
node->elem = *preorder;
int rootIndex = 0;
for(;rootIndex < length; rootIndex++)
{
regret用法
if(inorder[rootIndex] == *preorder)
break;
美式哥特}
//Left
BinaryTreeFromOrderings(inorder, preorder +1, rootIndex);
/
/Right
BinaryTreeFromOrderings(inorder + rootIndex + 1, preorder + rootIndex + 1, length - (rootIndex + 1));
cout<<node->elem<<endl;
return;
}
int main(int argc, char* argv[])
{
//printf("Hello World!\n");
//char* pr="GDAFEMHZ";
//char* in="ADEFGHMZ";
三元说char pr[MAX],in[MAX];
printf("请输入前序序列:\n");
gets(pr);
printf("请输入中序序列:\n");
gets(in);
宁波旅行BinaryTreeFromOrderings(in, pr, 8);
printf("\n");
return 0;
}
那年十八