标签:des style blog io color sp for 数据 div
1 2 2 1 20
2 1 20
#include <stdio.h> #include <stdlib.h> typedef struct node { int data; struct node *lchild; struct node *rchild; }Tree; int i, n, key, cnt = 0; Tree *Insert(Tree *t , int key) { if(t == NULL) { Tree *p; p = (Tree *)malloc(sizeof(Tree)); p->data = key; p->lchild = NULL; p->rchild = NULL; t = p; } else { if(key < t->data) t->lchild = Insert(t->lchild, key); else t->rchild = Insert(t->rchild, key); } return t; } void InOrder(Tree *t) { if(t!=NULL) { InOrder(t->lchild); cnt++; if(cnt==n) printf("%d\n", t->data); else printf("%d ", t->data); InOrder(t->rchild); } } int main() { while(~scanf("%d", &n)) { Tree * t = NULL; cnt = 0; for(i=0; i<n; i++) { scanf("%d", &key); t = Insert(t, key); } InOrder(t); } return 0; }
标签:des style blog io color sp for 数据 div
原文地址:http://www.cnblogs.com/6bing/p/4116759.html