I have an assignment with a slightly strange implementation of priority queues using a binary tree. I'm really having trouble trying to understand how to make my insert function work when the parameters are as follows
void insert(tree t, void* item)
where item is the data going to be inserted. The user of the library is supposed to be able to pass the data to the insert function with something like this:
insert(tree, (char*) "information");
The problem I'm having is that I don't understand how to deal with inserting (void*) item without it already being a malloc'd node (with pointers to the left and right already present). I can't throw a statement at the top of my insert function that automatically converts (void*) item into a node, because the insert function will have to recursively call itself until the node get put in the correct place. I wouldn't want to make a node out of something that's already a node.
Is there some kind of check i could do that determines if the void pointer that gets passed is already a node, or just another primitive type?
oh and this is how I have my tree struct setup, which could change if anyone has suggestions on how I could do this a little better so I could eliminate the problem all together.
struct tree{
void* left,right,data;
TreeType type;
};