/*********************************************************** * * * spipe takes a file of integers, sorts them, and * * outputs a sorted (n,fraction done) file * * * * * ************************************************************/ //Include the relevant includes #include struct tree { long int n; tree* l; tree* r; }; void add(tree* &t,long int m); //Add stuff to the tree void sort(tree* t,long int &c,long int size); //Print out tree main(){ long int inp; long int size,c; tree *T; size=0; T=(tree *) 0; //initialize to nil while(!cin.eof()){ cin >> inp; size++; add(T,inp); } cout << "about to sort" << endl; c=0; sort(T,c,size); } void add(tree* &t,long int m){ if(t==0){ t=new tree; t->n=m; t->l= (tree *) 0; t->r= (tree *) 0; } else if(t->n>m) add(t->l,m); else add(t->r,m); } void sort(tree *t,long int &c,long int size){ if(t!=0){ sort(t->l,c,size); c++; cout << t->n << " " << ((float) c)/size << endl; sort(t->r,c,size); } }