3 ms·
If there are a negative number of changes in bubble sort, why is returning early any more valid than continuing with the loop? Think about how bubble sort shoul
by krallja 9y ago
If there are a negative number of changes in bubble sort, why is returning early any more valid than continuing with the loop? Think about how bubble sort should work. There is no correct next step to take if count is negative. A negative count of changes is nonsensical. The only option that I could agree with, if you’re going to bother coding anything in this case, is to terminate execution, because the program is incorrect.
- pdkl95 9y ago> why is returning early any more valid than continuing with the loop? You could consider it an extension of the "0" condition. However... > terminate execution, because the program is incorrect. ...this is probably better than simply terminating the loop.