本文共 719 字,大约阅读时间需要 2 分钟。
#include
#include<stdio.h> #include<stdlib.h> typedef struct tree { int nValue; struct tree *pLeft; struct tree *pRight; }Tree; void CreateTree(Tree **ptree) { int num; scanf("%d",&num); if(num == 0)return; (ptree) = (Tree)malloc(sizeof(Tree)); (*ptree)->nValue = num; (*ptree)->pLeft = NULL; (*ptree)->pRight = NULL; CreateTree(&((ptree)->pLeft)); CreateTree(&((ptree)->pRight)); } void print(Treezhi){ if(zhi==NULL){ return ; } if(zhi!=NULL){ printf("%d ",zhi->nValue); print(zhi->pLeft); print(zhi->pRight); } } using namespace std; int main() { Tree ptree = (Tree)malloc(sizeof(Tree)); int a; cin>>a; ptree->nValue=a; treefirst=ptree; CreateTree(&ptree->pLeft); CreateTree(&ptree->pRight); print(first); return 0; }转载地址:http://lwyki.baihongyu.com/