Description
试编写程序,将两棵二叉排序树合并为一棵二叉排序树。
Input
按照先序序列,分两行输入两棵二叉排序树各结点(结点值大于0),其中-1表示取消建立子树结点。
Output
按照中序序列输出合并后的二叉排序树。
-
Sample Input
12 8 4 -1 -1 10 -1 -1 16 13 -1 -1 18 -1 -1 17 6 2 -1 -1 9 -1 -1 24 19 -1 -1 26 -1 -1
-
Sample Output
2 4 6 8 9 10 12 13 16 17 18 19 24 26
#include<stdio.h>
#include<stdlib.h>
typedef struct BinaryTree{
int num;
struct BinaryTree *lchild;
struct BinaryTree *rchild;
}BinaryTree,*Bintree;
void CreatBTree(Bintree *List){
int n;
scanf("%d", &n);
if(n == -1) *List = NULL;
else{
*List = (Bintree)malloc(sizeof(BinaryTree));
(*List)->num = n;
CreatBTree(&((*List)->lchild));
CreatBTree(&((*List)->rchild));
}
}
void insert(Bintree *List, int a){
if(!*List){