+ 1

What's wrong with my shell sort?

It appears that my shell sort still needs one final pass, but I'm not sure what to change to achieve this. Could anyone point me in the right direction? https://code.sololearn.com/cMrvFWe4Cb9J/?ref=app

5th Dec 2017, 10:14 PM
bornToCode()
bornToCode() - avatar
5 Answers
+ 2
Aha! That's what was missing, thank you very much.
5th Dec 2017, 11:38 PM
bornToCode()
bornToCode() - avatar
+ 1
You set your gap to n / 2. What if that number is odd? It will automatically round down when stored into an integer. Maybe you desire that effect, but maybe that's what is happening. I haven't really tried a shell sort myself.
5th Dec 2017, 11:12 PM
Zeke Williams
Zeke Williams - avatar
+ 1
Changing the division to odd doesn't help, unfortunately. No matter what, the final gap is the same. It's supposed to become a bubble sort after the gap is finished, but the sort stops just before the final pass for some reason.
5th Dec 2017, 11:26 PM
bornToCode()
bornToCode() - avatar
+ 1
I suppose I could call my bubbleSort() function after my broken shellSort() function, lol.
5th Dec 2017, 11:28 PM
bornToCode()
bornToCode() - avatar