#include<stdio.h> #include<stdlib.h> #include<malloc.h> typedef struct node { int data; struct node*lchild,*rchild; }tnode,*tree; tree creat() { int x; tree t; scanf("%d",&x); if(x==0)t=NULL; else { t=(tnode*)malloc(sizeof(tnode)); t->data=x; t->lchild=creat(); t->rchild=creat(); } return t; } int TreeNum(tree t,int *k) { if(t) { (*k)--;if(*k==0)return t->data; if(*k!=0)return TreeNum(t->lchild,k); if(*k!=0)return TreeNum(t->rchild,k); } return -1; } int main() { int n; tree t=creat(); printf("input a number: "); scanf("%d",&n); printf("%d ",TreeNum(t,&n)); }
版权声明:本文为博主原创文章,未经博主允许不得转载。