nodes in a bst
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
check for leaf: left == NULL OR right == NULL
check for not-leaf: left != NULL AND right != NULL
check for not-leaf: left != NULL AND right != NULL
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.
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.
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...
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...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement