#include<stdio.h>
#include<stdlib.h>

struct node{
            int val;
            struct node *left;
            struct node *right;
            };
            
void killtree(struct node *leaf){
     if(leaf->left!=NULL){
       killtree(leaf->left);
       }
     if(leaf->right!=NULL){
       killtree(leaf->right);
       }
     free(leaf);
}
            
void getorder(struct node *leaf, int *f, int *i){
     if(leaf->left!=NULL){
       getorder(leaf->left, f, i);
       }
     f[*i]=leaf->val;
     *i++;
     if(leaf->right!=NULL){
       getorder(leaf->right, f, i);
       }
}

void create(int co, struct node **leaf){
     if(*leaf==NULL){
       (*leaf)=malloc(sizeof(**leaf));
       (*leaf)->val=co;
       (*leaf)->left=NULL;
       (*leaf)->right=NULL;
       getchar();
       }
     else if(co<(*leaf)->val){
       create(co, &(*leaf)->left);
       }
     else if(co>=(*leaf)->val){
       create(co, &(*leaf)->right);
       }
}

void tree(int *f, int c){
     int i, *j;
     struct node *root;
     root=NULL;
     for(i=0;i<c;i++){
       create(f[i], &root);
       }
     j=malloc(sizeof(*j));
     *j=0;
     getorder(root, f, j);
     killtree(root);
}

int main(){
    int *pole, i, count=3;
    pole[0]=25;
    pole[1]=12;
    pole[2]=16;
    tree(pole, count);
    printf("Done!\n");
    printf("Zapis do souboru dokoncen!!");
    for(i=1;i<count;i++){
        printf("%d\t",pole[i]);
    }
    free(pole);
    return(0);
}