【发布时间】:2015-01-03 18:49:43
【问题描述】:
我试图根据我们的编程讲座使用排序算法。也许我只是错过了一些东西。
如果有人可以帮助我或就我犯的任何错误给我提示,我将不胜感激。
这是我当前的代码:
package Sortieralgorithmus;
public class sort {
public static int[] straightSelection(int[] numbers) {
for (int i = 0; i < numbers.length; i++) {
int smallestIndex = i;
for (int j = i + 1; j < numbers.length; j++) {
if (numbers[i] < numbers[smallestIndex]) {
smallestIndex = j;
}
}
swap(j, i, numbers);
}
return numbers;
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow!你的代码能运行吗?你得到什么错误?代码在运行时会做什么?你想让它做什么?您必须确保解决所有这些问题,我们才能为您提供帮助……否则,我们甚至不知道您在问什么。
-
什么不起作用?
-
1) 有什么问题? 2) 使用 Java 代码约定使您的代码更易于阅读;包是小写的,类以大写字母开头。
-
您是否在任何地方定义了
swap?你在两个地方混淆了i、j和smallestIndex。
标签: java algorithm sorting swap