#ifndef _Binary_Tree #define _Binary_Tree //#pragma once /* macros for general using */ #define _WaitForResponse { fprintf(stdout,"\n\n Press Any Key To Continue..."); getch(); } #define _Msg(msg) { fprintf(stdout,"\n\n"); fprintf(stdout,msg); }; #define _ErrMsg(msg) { fprintf(stderr,"\n\n"); fprintf(stderr,msg); _WaitForResponse exit(1); }; /* enums */ typedef enum { False, True } Boolean; typedef enum { Smaller = -1, Equals, Bigger } CmpResult; // cmp(first,second) => -1 if first < second, 0 if first = second, 1 if first > second typedef void* Value; // Generic Pointer(generic value) /* struct of the tree's leafs */ typedef struct Leaf{ Value value; struct Leaf *leftTree; struct Leaf *rightTree; }Leaf,Binary_Tree; /* typedef for Function_Pointer using */ typedef CmpResult (*Compare_Func)(Value,Value); typedef void (*Free_Func)(Value); typedef Value (*Create_New)(); typedef void (*Print_Function)(Leaf); typedef void (*Action_Func)(Leaf); /* general functions */ void init(Compare_Func *_cmpF, Free_Func *_freeF, Create_New *_crtNewF, Print_Function *_printF, Compare_Func cmpF, Free_Func freeF, Create_New crtNewF, Print_Function printf); Boolean insert(Binary_Tree **tree,Value value,Compare_Func cmpF); // insert value to a tree Boolean isExist(Binary_Tree *tree,Value value,Compare_Func cmpF); // checking if a value exists in a tree Leaf* createLeaf(Value value); // creating a tree Leaf void removeValue(Binary_Tree **tree, Value value,Compare_Func cmpF, Free_Func freeF); // remove value from a tree void destroyTree(Binary_Tree **tree,Free_Func freeF); // destroy a whole tree void inOrder(Binary_Tree *tree, Action_Func actoinF); // travle a tree with in-order track void postOrder(Binary_Tree *tree, Action_Func actionF); // // // // // post-order // // void preOrder(Binary_Tree *tree, Action_Func actionF); // // // // pre-order // // void printMax(Binary_Tree *tree, Print_Function printF); // print the tree values sorted from the max to the min void printMin(Binary_Tree *tree, Print_Function printF); // // // // // // // min to the max #endif