java - Infinite While Loop in Quick Sort -
i'm coding quick sort in java, , i've completed partitioning portion, reason, program keeps running forever with:
x swapped x
where x random integer, same integer every time printed. i've tried debug this, runs fine every time in debugger. doing wrong? here's code excluding parent class, array generator, etc.
class quicksort extends basicsort { public quicksort() { super("quicksort"); } public void sort() { int pivot = data[data.length / 2]; int low = 0, high = data.length - 1; while (true) { while (low < (data.length - 1) && data[low] < pivot) { system.out.println(data[low] + " less " + pivot); low++; } while (high > 0 && data[high] > pivot) { system.out.println(data[high] + " greater " + pivot); high--; } if (low >= high) { break; } else { int temp = data[low]; data[low] = data[high]; data[high] = temp; system.out.println(data[low] + " swapped " + data[high]); } } } }
this issue identical numbers, have write code condition. guys.
Comments
Post a Comment