“我们将在此程序中添加快速排序和合并排序(非递归)”。我不确定如何使用随机数组来做到这一点。到目前为止,我编写了这段代码,有人能帮上忙吗?
导入java.util.Random;公共类Algo {
public static void main(String[] args) {
Random gen = new Random();
int[] a = new int[20];
for (int i = 0; i < a.length; i++)
a[i] = gen.nextInt(100);
printArray(a);
}
private static void printArray(int[] a){
for (int i : a)
System.out.print(i + " ");
System.out.println("");
}
}}
发布于 2012-03-19 08:34:41
要生成随机元素数组,请尝试执行以下操作:
int[] array = new int[20];
Random random = new Random();
for (int i = 0; i < array.length; i++)
array[i] = random.nextInt();..。之后,您可以研究合并排序和快速排序算法。到目前为止,你做了什么?
public static void mergeSort(int[] array) {
// sorts the array in-place using merge sort algorithm
}
public static void quickSort(int[] array) {
// sorts the array in-place using quick sort algorithm
}https://stackoverflow.com/questions/9763504
复制相似问题