I have made this:
if (parent[x] == &N::sentinel) {
/* Update root. */
parent[(*this).header] = y;
} else {
if (x == left[parent[x]]) {
left[parent[x]] = y;
} else {
right[parent[x]] = y;
}
}
but I don't really like it. Any suggestions for making it look better
and more clear?
There's nothing wrong with this. It's got the
K&R style of brackets, and my personal bias is
to line brackets up vertically. So I do it so:
if(parent[x] == &N::sentinel)
{
// if stuff here
}
else
{
// else case stuff here
}
And so on. But this is just a personal bias.
It's not something I'd suggest changing for
existing code that works.
Unless you have some mods to make, I'd suggest
leaving it alone. Working code shouldn't be
touched for "elegance" reasons. If it's doing
what it is supposed to do, and satisfying the
requirements of performance etc., don't risk
adding bugs.
Remember, every bug in your code was put there
by you.
If you have changes to make, where you go depends
on what you need to do. For example, if you were
to need to add a lot of new logic cases, you might
consider something like a table driven system.
Or if the processing for each case got much more
complicated you might consider putting in a function
to do the processing and keep the logic decisions
as simple and clear as reasonably possible. Or you
might consider that you need a state engine of some
kind, and maybe a class to handle it.
Socks