Re: "Sorting" assignment



spinoza1111 wrote:
On Feb 7, 7:17 pm, "Clive D. W. Feather" <cl...@on-the-
train.demon.co.uk> wrote:

bool bubble;

do
{
bubble = false;
for (int i = 0; i < arraySize - 1; i++)
if (array [i] > array [j])
{
exchange (i, j);
bubble = true;
}}

while (bubble);

(2) The last value for i is the arraySize minus one but this is wrong
insofar as I can determine your intent from bug number 3. Because of
zero-origin indexing that should be arraySize minus two.

(3) You failed to compute j at all.


No, the last value for i is arraySize-2 in the above loop.

--
Bart


.



Relevant Pages

  • Re: "Sorting" assignment
    ... bubble = false; ... The last value for i is the arraySize minus one but this is wrong ... insofar as I can determine your intent from bug number 3. ... but the de minimis bug remains. ...
    (comp.programming)
  • Re: "Sorting" assignment
    ... bubble = false; ... exchange; ... The last value for i is the arraySize minus one but this is wrong ...
    (comp.programming)