you count the zero and then 'uncount' it.
so if you have 1 2 3 0
it counts to 4, subtracts 1, and cooks up the answer of 3.
there is probably a way to write it cleaner.
does it give the correct n if you put in maxsize items? Try it, set maxsize to something small like 5 and test it if you don't see what it will do... if n == maxsize, what does line 22 do? (I am trying to tell you the code is probably bad...)
there is probably a way to write it cleaner.
does it give the correct n if you put in maxsize items? Try it, set maxsize to something small like 5 and test it if you don't see what it will do... if n == maxsize, what does line 22 do? (I am trying to tell you the code is probably bad...)
As you said the program gives the wrong result when n==maxsize. The example is taken from a book. Thanks for the hint. At present, though, with my current knowledge of cpp coding, I have no clue on how to improve it.
the first thing about improving code is to fix screw ups and make it RIGHT.
making it prettier or faster comes after that.
can you fix it so it does not screw up?
Side note: always question, books have as much bugged up code as anything else.