好吧,我誤解了這個問題。讀了幾次後,我發現randInt
實際上是我用來填充數組的方法。所以當它說打電話randInt
它的某種遞歸電話我想。這是它應該看起來像什麼:交換數組中的引用
static int[] randInt(int i, int j) {
int[] temp = new int[(j - i) + 1];
for (i = 0; i < j; i++) {
temp[i] = i + 1; // here i populate the array
}
System.out.println(Arrays.toString(temp)); // this prints [1, 2, 3, 4, 5]
for (i = 1; i < j;i++){
swapReferences(temp[i], temp[randInt(0,i)]); //this is some sort of recursive call that swaps the references
// btw that statement does not compile, how can i pass a method as a parameter?
}
return temp;
}
static void swapReferences(int a, int b) { //these parameters are wrong, need to be changed
//Method to swap references
}
對不起,我認爲這是如何應該是正確的。
@SotiriosDelimanolis不是它的一個不同的問題。 – user1404664
你會這麼想,但你會錯的。 –
不同_scenario_,同樣的問題。 – csmckelvey