Start by indenting your code: "flat to the left hand side" doesn't help anyone understand your code, especially you.
Which of these is easier to read?
int IsEmpty(){
if(antrian.tail==-1)
return 1;
else
return 0;
}
int IsEmpty(){
if(antrian.tail==-1)
return 1;
else
return 0;
}
int IsEmpty()
{
if(antrian.tail==-1)
{
return 1;
}
else
{
return 0;
}
}
Here is a clue: It's not the first one ...
Indentation helps everybody see what is going on more clearly: where functions begin and end, what is - and isn't - inside a
struct
, how the code flow works.
So pick an
indentation style[
^] and stick to it. (I like Whitesmiths, but it's not to everybody's taste) It'll make your coding a lot easier once you get used to the idea. And at least while you are beginning,
always use curly braces for code in an
if
,
else
, or similar, even if it's one line: it's far too easy to miss something if you don't:
if (a == b)
c = 2; d =3;
is not the same as
if (a == b)
{
c = 2; d =3;
}
Or better
if (a == b)
{
c = 2;
d =3;
}
And forget
label
s, forget
goto
- pretend they don't even
exist for a couple of years - no code you are going to write will need one, there are loads of ways to loop that won't make people laugh at your code or (in extreme cases) beat you with a cluebat until blood comes out your ears.
When you've done all that, you'll probably have already fixed the problem you've noticed without even being aware of it ...