viewing paste Unknown #921 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
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);
        }
Viewed 735 times, submitted by Guest.