二叉树

#include<stdio.h>
typedef struct Node{
char data;
struct Node *LChild;
struct Node *RChild;
}BiTNode,*BiTree;

void createBiTree(BiTree *bt){
	char ch;
	ch = getchar();
	if(ch == '.'){
		(*bt) = NULL;
	}
	else{
	*bt = (BiTree)malloc(sizeof(BiTNode));
	(*bt)->data = ch;
	createBiTree(&((*bt)->LChild));
	createBiTree(&((*bt)->RChild));
	}
} 
void preOrder(BiTree tree){
	if(tree != NULL){
		printf("%c ", tree->data);
		preOrder(tree->LChild);
		preOrder(tree->RChild);
	}
}

int main(){
	BiTree root;
	createBiTree(&root);
 	preOrder(root);
	return 0; 
	
}
 

你可能感兴趣的:(二叉树)