Quote:
Been debugging all day
This sentence tells that you don't know how to use the debugger.
The debugger will not find bugs by magic ! it only allow you to see what your code is doing !
You have to take advantage of it!
Quote:
I want the algorithm to be stable (i.e. the relative order of items with the same key is kept).
First, if you look at documentation
Quicksort - Wikipedia[
^], you will see that by definition, QuickSort is not stable !
Advices:
- This:
var i = 0;
for (i; i < size; i += 1) {
should be rewritten as:
for (i=0; i < size; i += 1) {
or
for (i=0; i < size; i ++) {
because it is considered easier to read.
- You should write a wrapping function which take a list as parameter and return a sorted list as result. It simplify reuse and testing.
-Take a sheet of paper build a test list and plan what would do the program to solve the problem, then, as you run the test, use the debugger to check if the program behave as expected.
Start with small test lists:
{1}
{1, 5}
{5, 1}
{1, 4, 9}
{1, 9, 4}
{4, 1, 9}
{9, 4, 1}
...
[UpDate]
Why do you have this line ?
ints[4].value = ints[size - 1].value;
For me, it kills
ints[4]
.
I have doubt about your test to
pindex
on the 2 while loops.
[UpDate]
Try to sort this sequence: {0, 2, 4, 6, 1, 3, 5}
If there is a problem, it will confirm the doubt I expressed in previous update.
Let me know the result.