We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer,
your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
[Update]
Advice: Indent your code properly, indentation shows the structure of your code and makes it easier to read.
Node *insert(Node *Tree, void *Object, float (*Distance)(void *, void *))
{
if(Tree == NULL){
if((Tree=(Node *)malloc(sizeof(Node)))==NULL){
printf("Insufficient memory");
exit(1);
}
Tree->p1 = Object;
Tree->p2 = NULL;
Tree->left = Tree->right =NULL;
}
else if (Tree->p2 == NULL)
Tree->p2 = Object;
else if ((*Distance)(Tree->p1, Object) < (*Distance)(Tree->p2, Object))
insert(Tree->left, Object, Distance);
else insert(Tree->right, Object, Distance);
return(Tree);
}
Professional programmer's editors have this feature.
Notepad++ Home[
^]
UltraEdit | The Original Text Editor[
^]
Advice: do not pack more code than needed in 1 line, it saves nothing and is not faster, it is just more difficult to read.
Node *insert(Node *Tree, void *Object, float (*Distance)(void *, void *))
{
if(Tree == NULL){
Tree=(Node *)malloc(sizeof(Node));
if((Tree == NULL){
printf("Insufficient memory");
exit(1);
}
Tree->p1 = Object;
Tree->p2 = NULL;
Tree->left = Tree->right =NULL;
}
else if (Tree->p2 == NULL)
Tree->p2 = Object;
else if ((*Distance)(Tree->p1, Object) < (*Distance)(Tree->p2, Object))
insert(Tree->left, Object, Distance);
else
insert(Tree->right, Object, Distance);
return(Tree);
}
Advice: do not learn programming with C language. With C language, you are responsible of every details like memory management, array boundaries, memory leak and so on. Handling those details makes learning more difficult.
Use instead real high level language like BASIC, Java or C#, they are marshaled and tell you when something go wrong like reading after the end of an array.