private int[] Splitter(){
//Use split method to put the String into String array separated with " " delimeter
String inputString = inputsjTextField.getText();
String[] stringParts = inputString.split(" ");
//Convert String array to int array
int[] inputs = new int[stringParts.length];
for (int i=0; i < stringParts.length; i++) {
inputs[i] = Integer.parseInt(stringParts[i]);
//System.out.println(inputs[i]);
}
return inputs;
}
//QUICK SORT PART----------------------------------------------------------------------------------------------------
private int[] minmax(){
int arr[] = Splitter();
return doQuickSort(0, arr.length - 1);
}
private int[] doQuickSort(int start, int end){
int arr2[] = Splitter();
//1st Error-Pivot Point was wrong
//Pivot
int temp = (start+end)/2;
int pivot = arr2[temp];
int i = start, j = end;
while (i <= j) {
while (arr2[i] < pivot)
i++;
while (arr2[j] > pivot)
j--;
if (i <= j) {
swap(i, j, arr2);
i++;
j--;
}
}
//2nd Error-End of Braces here
if (start < j)
doQuickSort(start, j);
if (i < end)
doQuickSort(i, end);
return arr2;
}
private void swap(int i, int j, int arr2[]) {
int temp = arr2[i];
arr2[i] = arr2[j];
arr2[j] = temp;
}
private void executejButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Object value = algojComboBox.getSelectedItem();
if(value == "Quick Sort"){
int arr3[] = minmax();
String outputSortedElements="";
for(int i=0; i<arr3.length; i++) {
outputSortedElements+=arr3[i];
outputSortedElements+=", ";
}
sortedjTextField.setText(outputSortedElements);
//System.out.println(value);
}