• Advertisement

Archived

This topic is now archived and is closed to further replies.

nodes in a bst

This topic is 5692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok when i have a binary tree created, i check for a leaf by seeing if its left or right is null. however why doesnt the same theory work for checking if its a node? like why doesnt this work if node-> right !=NULL or node->left !=null

Share this post


Link to post
Share on other sites
Advertisement
check for leaf: left == NULL OR right == NULL
check for not-leaf: left != NULL AND right != NULL

Share this post


Link to post
Share on other sites
doing that only works for if its a leaf tho.
i had to swap the && and || to get it to work for a leaf but i stil cant get it to properly do a node.

Share this post


Link to post
Share on other sites
ok, maybe i''m a bit rusty one this... each item in a BST is a node, and a node with no sub-trees is a leaf, right? so wait... i meant:
leaf: left == NULL AND right == NULL
node: left != NULL OR right != NULL
yah, so if both left & right are NULL, it is a leaf (no subtrees), otherwise it is a node (if either is not NULL)...
er... i need some sleep already...

Share this post


Link to post
Share on other sites
anyone know of a good website about this , every time i do a search i get game related stuff with quake and i dont need that kind of info.

Share this post


Link to post
Share on other sites

  • Advertisement