nodes in a bst

Started by
4 comments, last by omegasyphon 21 years, 9 months ago
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
Advertisement
check for leaf: left == NULL OR right == NULL
check for not-leaf: left != NULL AND right != NULL
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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.
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...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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.
Check this site out.

This topic is closed to new replies.

Advertisement