Can I do boolean tests in a struct?
Dec 4, 2012 at 11:30pm UTC
Basically, here's what I want.
I want to make a binary tree node struct that has a dynamic pointer inside of it that points to the next free node.
I figured that this: could work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
struct TreeNode {
TreeItem goodies;
TreeNode * left;
TreeNode * right;
TreeNode * next;
if (*left ==NULL)
*next = *left;
else if (*right ==NULL)
*next = *right;
else
*next = NULL;
//Constructor stuff omitted
}
Can it ?
Dec 4, 2012 at 11:53pm UTC
yes, you can do boolean tests.But that should be in some function.
Also
1 2 3 4 5 6
if (*left ==NULL)
*next = *left;
else if (*right ==NULL)
*next = *right;
else
*next = NULL;
needs to be modified as we compare the NULL pointer with pointer only, not content ,so '*' should be removed as shown below.
1 2 3 4 5 6
if (left ==NULL)
next = left;
else if (right ==NULL)
next = right;
else
next = NULL;
Last edited on Dec 4, 2012 at 11:54pm UTC
Topic archived. No new replies allowed.