#include <bits/stdc++.h> using namespace std; int l; int a[10086]; typedef struct node { int data; struct node *lc,*rc; }tree; tree *creat(tree *root,int k) { if(root==NULL) { root=new tree; root->data = k; root->lc = root->rc = NULL; } else { if(root->data>k) { root->lc = creat(root->lc,k); } else{ root->rc = creat(root->rc,k); } } return root; } void inordertraval(tree *root) { if(root) { inordertraval(root->lc); //printf("%c",root->data); a[l++] = root->data; inordertraval(root->rc); } } int main() { int i,n,k; struct node *root; root = new tree; while(scanf("%d",&n)!=EOF) { l=0; root = NULL; for(i=0;i<n;i++) { scanf("%d",&k); root=creat(root,k); } inordertraval(root); for(i=0;i<l;i++) { printf(i==0?"%d":" %d",a[i]); } printf("\n"); } return 0; }
转载于:https://www.cnblogs.com/CCCrunner/p/6444585.html
相关资源:JAVA上百实例源码以及开源项目