Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on this one I need a return statement that returnsthe sorted array a

ID: 3613857 • Letter: I

Question

I need help on this one I need a return statement that returnsthe sorted array and I cant figure out how to get around thaterror.....HELP

public class BubbleSort {   /** The method for sorting the numbers */   public void bubbleSort(Comparable[] V){    boolean needNextPass = true;
   for (int k = 1; k < V.length &&needNextPass; k++) {    // Array may be sorted and next passnot needed    needNextPass = false;    for (int i = 0; i < V.length - k;i++) {    if (V[i] > V[i + 1]){-------------------------------------- operator > cannotbe applied to java.lang.Comparable,java.lang.Comparable
   // Swap list[i] withlist[i + 1]    Comparable temp =V[i];    V[i] = V[i + 1];    V[i + 1] = temp;
   needNextPass = true;// Next pass still needed    }    }    }   } } I need help on this one I need a return statement that returnsthe sorted array and I cant figure out how to get around thaterror.....HELP

public class BubbleSort {   /** The method for sorting the numbers */   public void bubbleSort(Comparable[] V){    boolean needNextPass = true;
   for (int k = 1; k < V.length &&needNextPass; k++) {    // Array may be sorted and next passnot needed    needNextPass = false;    for (int i = 0; i < V.length - k;i++) {    if (V[i] > V[i + 1]){-------------------------------------- operator > cannotbe applied to java.lang.Comparable,java.lang.Comparable
   // Swap list[i] withlist[i + 1]    Comparable temp =V[i];    V[i] = V[i + 1];    V[i + 1] = temp;
   needNextPass = true;// Next pass still needed    }    }    }   } }

Explanation / Answer

public class BubbleSort {   /** The method for sortingthe numbers */   public voidbubbleSort(Comparable[] V) {    boolean needNextPass =true;
   for (int k = 1; k <V.length && needNextPass; k++) {    // Array may besorted and next pass not needed    needNextPass =false;    for (int i = 0;i < V.length - k; i++) {
        // fixed ifstatement
   if (V[i].compareTo(V[i+1])>0){
     // Swap list[i] with list[i + 1]      Comparable temp = V[i];      V[i] = V[i + 1];      V[i + 1] = temp;
     needNextPass = true; // Next pass still needed      }    }    }   } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote