Reputation: 11
Im a newbie at programming and working at an implementation for AVL Trees atm. I got alot of problems and asking for help at 1 of them, maybe I will be able to fix the other ones too after that, since they all sound pretty similiar.
I have the following function for printing the Tree InOrder:
void AVL_in_order_walk(AVLTree* avlt)
{
if(avlt!=NULL){
AVL_in_order_walk(avlt->root->left);
printf("%d",avlt->root->value);
AVL_in_order_walk(avlt->root->right);
}
}
Which seems to be pretty wrong. I got following warnings:
passing argument 1 of ‘AVL_in_order_walk’ from incompatible pointer type [enabled by default]
AVL_in_order_walk(avlt->root->left);
I got several errors/warnings/notes like this one. I think I have one big problem simply understanding this: When I have a function like the in_order_walk I posted above, the function doesnt get a node, it gets the whole tree. I alrdy worte a few walks through trees, or insertFunctions, but the function always had a node to start from, because it was called like "void Function(Node* X)". Now I have the whole tree (AVLTree* avlt) and I dont seem to be able to use recursion because of that, am I wrong?
Btw: Structs for Tree and Node:
struct AVLTree
{
struct AVLNode* root;
int numberOfNodes;
};
struct AVLNode
{
struct AVLNode* left;
struct AVLNode* right;
struct AVLNode* parent;
int value;
int height;
};
How its called:
void AVL_in_order_walk(AVLTree* avlt);
I would really really appreciate any kind of help since I just dont get it..
Upvotes: 0
Views: 516
Reputation: 170084
void AVL_in_order_walk(AVLTree* avlt)
is declared to accept a AVLTree*
, but you try to pass it a AVLNode*
. Your compiler is telling those are pointers to different types.
I suggest you add a hidden function that can be called recursively, and does the actual work.
static void AVL_in_order_walk_implementation(AVLNode* avlt) {
/* Implement the walk */
}
extern void AVL_in_order_walk(AVLTree* avlt) {
if(avlt)
AVL_in_order_walk_implementation(avlt->root);
}
Upvotes: 2