Android: so erstellen Sie einzigartige zufällige zahlen in ein array und bubble sort durchführen?
Folgendes ist mein code, aber es nicht erzeugen einzigartige Zufallszahlen
Random rand = new Random();
int[] array = new int[n];
for (int i = 0; i < n; i++){
array[i] = rand.nextInt(n)+1;
}
for (int i = 0; i < ( n - 1 ); i++)
{
for (int j = 0; j < n - i - 1; j++) {
if (array[j] > array[j+1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
- Was hat es zu generieren?
- Warum machst du bubble-sort?
- n ist nie initilized
Du musst angemeldet sein, um einen Kommentar abzugeben.
check this out!... es funktioniert für mich