Algoritma Mengacak Urutan Data Array Java




static void AcakArray(int[] ar,int[] urutan)
{
    Random rnd = new Random();
    for (int i = ar.length - 1; i > 0; i--)
    {
        int index = rnd.nextInt(i + 1);
        // Simple swap        int a = ar[index];
        int b = urutan[index];

        ar[index] = ar[i];
       urutan[index] = urutan[i];

        ar[i] = a;
        urutan[i] = b;
    }
}

Tidak ada komentar