user1258734
user1258734

Reputation: 13

JUnit Test error

I am trying to run a JUnit test for my program, however I am getting error message like

*incompatible types
required: int[];
found: int *

Here is the code that shows the error

myQSArray = QS.quickSort(sortedArray2,0, sortedArray2.length - 1);

and here is my call for quickSort method

public static int quickSort( int A[], int p, int r){
    int q; 
    if (p<r)
    {
         q = partition(A,p,r);
         quickSort(A, p, q-1);
         quickSort(A,q+1,r);
    }
    return QS1.quickSort(A, p, r);
}

Help Please, thanks in advance

Upvotes: 1

Views: 476

Answers (2)

Andreas Dolk
Andreas Dolk

Reputation: 114757

I see a couple of problems with your code:

The method is declared to return an int value but you try to assign this int to an int[]. That causes the actual compiletime error. Change the method signature to

public static int[] quickSort( int A[], int p, int r)

for a quick fix.

Then, your recursive function quicksort misses the exit criteria. It will run indefinitely (or at least until the virtual machine gives up and throws a StackOverflowException after a couple of milliseconds). You need to add a criteria to check, if the array is sorted and return the sorted array (see the "new" method signature!).

Upvotes: 1

mohan.reddy8
mohan.reddy8

Reputation: 23

Java Error incompatible types occurred when a compiler found a variable and expression whose data type is not compatible to perform an operation on them.And this is the one of the way.

better once refer you declared the "sortedArray2" as int[] array type or not

Upvotes: 0

Related Questions