On Feb 16, 7:37 pm, Jeff Schwab
[...]
> Near the top of the file where ConvertBinaryTree2LinkedList is defined,
> add the following header inclusion. Make sure the # is in the first
> column of the file, i.e. all the way on the left:
Why? It's usually considered good style to start include
directives in column 1, but you make it sound like there's more
too it (and of course, if the include is conditional, a lot of
people would indent it).
[...]
> (2) It is usual to leave space before opening braces.
> You have:
> if (condition){
> The following is more popular:
> if (condition) {
> The same is true for struct and class defintions,
Depending on who's writing the code, it might also be usual to
put the opening brace on a separate line. I write it like you
suggest, but I've also work in companies where the rule was no
space, and in other companies where the rule was to put the
opening brace on a line by itself. There's no consensus about
this, except for the rule that you should be consistent, and
always do it the same way.
> (3) There is no need to use the macro NULL. C++ has a null
> pointer literal: 0.
Readability. Almost all of the professionals I work with prefer
NULL---and I know I do.
> Instead of:
> btree* head =3D NULL:
> Many people prefer:
> btree* head =3D 0;
And many more don't. In this case, you know that 0 is actually
going to be used as a pointer---why do you want to hide that
fact from the reader. (Of course, if you don't care if anyone
can understand your code...)
> (4) There is no need to test whether a pointer !=3D 0, since
> non-null pointer values are implicitly converted to
> "true" in the context of a boolean test. You have:
> if (cursor !=3D NULL) {
> Many prefer:
> if (cursor) {
Every coding guideline I've ever seen bans that practice. A
pointer is not a boolean, even if the language (stupidly) allows
it to be converted to one. Just because a misfeature is present
doesn't mean you have to use it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34