Posts

Showing posts with the label quicksort

Quicksort implementation program array out of bounds error and not sorting generated numbers

Quicksort implementation program array out of bounds error and not sorting generated numbers I am new to programming and cannot seem to figure out my errors when trying to write a Quicksort program. I have most of the implementation done with the exception of a few errors that I cannot seem to figure out. Here is my current code: public class Quicksort { public static void main(String args) { Integer numbers = new Integer[20]; for (int i = 0; i < numbers.length; i++) { numbers[i] = (int) (Math.random() * 100); } printArray(numbers); quicksort(numbers); printArray(numbers); } public static <T> void printArray(T array) { for (int i = 0; i < array.length; i++) { System.out.print(array[i] + (i < array.length - 1 ? ", " : "n")); } } public static <T> void printArrayPartition(T array, int low, int high, int pivot) { for (int i = 0; i ...