How do I fix this bug? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

23rd Jan 2023, 9:46 AM
Alexx
Alexx - avatar
4 Answers
+ 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.
23rd Jan 2023, 1:09 PM
Scott D
Scott D - avatar
+ 1
Line 37 has a print statement
23rd Jan 2023, 10:46 AM
Anthony Dempsey
+ 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
23rd Jan 2023, 3:33 PM
Alexx
Alexx - avatar
0
Anthony Dempsey yes, it's because I swapped elements just above it, thanks though
23rd Jan 2023, 12:31 PM
Alexx
Alexx - avatar