标签:排序二叉树
#include<iostream> using namespace std; int f; typedef struct BiTNode { int data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; void visit(BiTree T) { if(T->data!=NULL) { if(f==1) { cout<<" "<<T->data; } else { cout<<T->data; f=1; } } } void insert(BiTree &T,int key) { if(T==NULL) { T=new BiTNode; T->lchild=T->rchild=NULL; T->data=key; return ; } if(key<T->data) insert(T->lchild,key); else insert(T->rchild,key); } void InOrder(BiTree T) { if(T) { InOrder(T->lchild); visit(T); InOrder(T->rchild); } } int main() { int m,i,n; BiTree T; while(cin>>m) { T=NULL; for(i=0;i<m;i++) { cin>>n; insert(T,n); } f=0; InOrder(T); cout<<"\n"; } return 0; }
标签:排序二叉树
原文地址:http://blog.csdn.net/r_misaya/article/details/40622883