Debug this code pls

This is the code of quicksort that I wrote. It stops working (not malfunction, but completely stops working on my offline ide i.e code::block). There seems to be some indexing or other memory-related error due to this small change, please help me figure out.

Hey @anshufirefox
Mentioned the changes in comments :https://ide.codingblocks.com/s/381040 :slight_smile:

Yeah, that’s the question. Why does it stop working with end limit as e instead of e-1. I know that placing of pivot would be disturbed probably, but why does a memory-related error occur

Assume all element are already sorted and hence smaller then arr[e] then i will reach e inside loop
then out of loop u try to swap
arr[e] and arr[i+1]
but arr[i+1] is out of bounds hence segmentation

1 Like

Thank you so much, I understood it. One last question. Does the compiler show error only when encountered with such case as input or does it show error in every case. My code stopped working even with the simplest input.

No
see it will give error in those cases only but see
Ur Right sub array of some sub call might be in that format in current case that’s why error

my input was
6
5
4
3
2
1

after ist iteration it will become
1 5 4 3 2 6

Yeah, I can see it happening in a subarray at 3rd level of recursion, when a sorted subarray is encountered. This is what is creating problem right?

yeah correct. … . …

Thank You so very much, Allow me to close this thread, and if it helps, I could fill the ratings.

1 Like

Yeah u can @anshufirefox :slight_smile:

There’s some link that the TA bhaiyas usually send

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.