0
How do I fix this bug?
I implemented quick sort using the lomuto partitioning scheme, and I want to print the array only when there is a swap. But I seem to keep printing the array repeatedly when no swap occurs. https://code.sololearn.com/c6GAu6BLZCCU/?ref=app
4 odpowiedzi
+ 5
Alexx
So did you solve it then Alexx? I'm curious to know, I found the code interesting. I noticed commenting out the last several lines seems to work, almost like they're feeding back into the function (although maybe that's the intent? ). Commenting out only the print array line doesn't fully solve the issue.
/* print_array(A, size);
lomuto(A, low, j - 1, size);
lomuto(A, j + 1, high, size);*/
But admittedly I haven't fully wrapped my head around the code so I'd be curious to know.
+ 1
Line 37 has a print statement
+ 1
Scott D I still haven't figured it out, the line you commented out is a recursive call to sort each half after the lomuto partition, if the array is modified you see it doesn't sort it. Thank you for helping
0
Anthony Dempsey yes, it's because I swapped elements just above it, thanks though