Re: simplebinary tree



CBFalconer <cbfalconer@xxxxxxxxx> writes:

/* if the node to be deleted has no child. */
if (x->left == NULL && x->right == NULL) {
if (parent->left == x) parent->left = NULL;
else parent->right = NULL;
free(x);
return;
}

This style I find simply unreadable. Almost impossible to spot "from
afar" the logical flow.

,----
| if (x->left == NULL && x->right == NULL) {
| if (parent->left == x){
| parent->left = NULL;
| }else{
| parent->right = NULL;
| }
| free(x);
| return;
| }
`----

Easy to see the control flow. Brackets already there for any later
additions with no bracketing errors. Debugger friendly. The first set of
code would not have been accepted by any of the wide ranging standards I
have ever used on personal and professional code bases. Advice to nOObs
: consider the two above and draw your own conclusions. Style can be a
personal thing : but in the real world where other people might be
responsible for extending or fixing your code then the second style is
100% better and more readable than the first - no questions. And anyone
that argues the first is more clear is almost certainly inexperienced in
multi-programmer projects.



.