#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); } } 这种建立的方法最烦人的地方莫过于判断结束的时候输入‘#‘的个数了,并且要按照先序的方法输入。
时间: 2024-12-22 22:03:02