Java – get this compile error in Java

compiler-errorsjavasorting

I get the following error:

quicksort(int[],int,int)cannot be applied to(int[])

When I compile this:

import java.util.*;

public class Sort {

public static void main(String[] args){

Random rand = new Random();
int[] tab = new int[10];

for(int i = 0; i < tab.length; i++) {
tab[i] = rand.nextInt(100);

System.out.println("Before: ");
show(tab);

quicksort (tab);
System.out.println("After: ");
show(tab);
  }
}
static void quicksort(int tab[], int x, int y) {

        int i,j,v,temp;

        i=x;
        j=y;
        v=tab[(x+y) / 2];
        do {
            while (tab[i]<v) 
                i++;
            while (v<tab[j]) 
                j--;
            if (i<=j) {
                temp=tab[i];
                tab[i]=tab[j];
                tab[j]=temp;
                i++;
                j--;
            }
        }
        while (i<=j);
        if (x<j) 
            quicksort(tab,x,j);
        if (i<y) 
            quicksort(tab,i,y);
    }


static void show (int tab[]) {
for (int i = 0; i <tab.length; i++) {
System.out.println(tab[i]);

  }
 }
}

What am I doing wrong?

Best Solution

Just after the line to print out "before", you have:

quicksort (tab);

The function you designed needs three arguments. You can either add the extra arguments:

quicksort (tab, 0, tab.length - 1)

Or add a new function such as:

public quicksort(int[]) {
  quicksort(tab, 0, tab.length - 1);
}