【发布时间】:2015-04-30 20:53:40
【问题描述】:
总的来说,每当我调用此方法对数组进行排序时,它都会停止,就好像它在等待响应一样。知道为什么它不起作用吗?
public void bubbleSort(){
boolean finished = false;
boolean swapOccurred = false;
int i = 0;
int next = i + 1;
while (finished == false)
{
for (; i < theArray.length - 1; i++)
{
if (theArray[i] > theArray[next])
{
swapValues(theArray[i], theArray[next]);
swapOccurred = true;
}
}
if (swapOccurred == false)
{
finished = true;
}
}
}
private void swapValues(int i, int next) {
int temp;
temp = i;
i = next;
next = temp;
}
【问题讨论】:
-
好吧,我们没有看到你的主要内容。
-
对不起!我将添加多少主要内容?我只创建一个新对象并调用 bubbleSort();方法。
-
还可以考虑为它所在的语言添加一个标签。我们可以猜测,但我们为什么需要呢?
-
再次抱歉!我对此很陌生,没有意识到。已更新,谢谢!
标签: java methods swap bubble-sort