The algorithm is wrong from the very beginning, the signature, as the sort method should not depends on any initial indices. The input should get a list parameter and nothing else. In some implementations, you will need to create another function for recursive calls.
I don't know what algorithm description did you use, but there are the pseudo-codes for different versions of the algorithm, pretty simple:
http://en.wikipedia.org/wiki/Quick_sort[
^].
Also, do you use the debugger during development? You should. The problem is pretty simple, you should better solve it to the very end. By yourself.
[EDIT]
I took the original code (still, it's not good enough, you should do what I mentioned about the signature), it worked out immediately after I changed it to use
List
. First, use
System.Collections.Generic.List<IComparable>
, as in original code. Change array declaration into list, add population of the list using
AddRange
and don't do anything else. Most importantly,
do not return unsorted. The algorithm works on arrays, so it does not use any list features and does not create any arrays, so you should not create any lists. The algorithm works in-place.
Make the return type void. Show
the same list after sorting as the one you've shown before — it will be sorted.
—SA