J
jova
I'm try to make it short.
Why is my root ok on one pass bu,t then changes to some weird number after
additional calls to the insert function?
I made root a global variable pointer.
struct binaryNode *root;
The first thing I did was set it NULL in the main.
root = NULL;
Then I use a integer and my root as a arguments in my insert method to
create the a Tree.
void insert(int x, struct binaryNode *node)
{
if(root==NULL)
{
root = node;
root -> value = x;
}
.......
}//end of insert I've cut the function just like you see here and the root
still changes
This is how I call the insert method
.......
struct binaryNode tempNode = createNode();
insert(number, &tempNode);
.......
And here his the createNode function.
struct binaryNode createNode()
{
struct binaryNode *t;
t = (malloc(sizeof(struct binaryNode)));
return *t;
}
Any Help is appreciated.
Why is my root ok on one pass bu,t then changes to some weird number after
additional calls to the insert function?
I made root a global variable pointer.
struct binaryNode *root;
The first thing I did was set it NULL in the main.
root = NULL;
Then I use a integer and my root as a arguments in my insert method to
create the a Tree.
void insert(int x, struct binaryNode *node)
{
if(root==NULL)
{
root = node;
root -> value = x;
}
.......
}//end of insert I've cut the function just like you see here and the root
still changes
This is how I call the insert method
.......
struct binaryNode tempNode = createNode();
insert(number, &tempNode);
.......
And here his the createNode function.
struct binaryNode createNode()
{
struct binaryNode *t;
t = (malloc(sizeof(struct binaryNode)));
return *t;
}
Any Help is appreciated.