c语言二叉树的递归建立

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>


typedef struct node{ TYPE data; struct node *leff; struct node *right; }Node,*pNode; typedef char TYPE; typedef struct node{ TYPE data; struct node *leff; struct node *right; }Node,*pNode; void createTree(pNode &root){ char l; char r; TYPE data; root = (pNode)malloc(sizeof(Node)); memset(root,0,sizeof(Node)); printf("Input root data:\n"); scanf("%c",&data); getchar(); if(data=='#'){ root = NULL; return ; } else{ root->data = data; createTree(root->leff); createTree(root->right); } }


这种建立的方法最烦人的地方莫过于判断结束的时候输入'#'的个数了,并且要按照先序的方法输入。

 

posted @ 2015-02-18 18:17  hudiwei-hdw  阅读(376)  评论(0编辑  收藏  举报