用java快速排序法,求十个数中的最大值
收起
知与谁同
2018-07-16 09:43:58
2315
0
2
条回答
写回答
取消
提交回答
-
public class QuickSort {
private int[] list = {};
public void setList(int[] list){
this.list = list;
}
public int[] getList(){
return this.list;
}
public void sort(int left, int right){
if(left > right) return;
int i = left;
int j = right;
int tmp = list[left];
int t;
while(i != j){
while(list[j] >= tmp && i < j) j--;
while(list[i] <= tmp && i < j) i++;
if (i < j){
t = list[i];
list[i] = list[j];
list[j] = t;
}
}
list[left] = list[i];
list[i] = tmp;
sort(left, i -1);
sort(i+1, right);
}
}
2019-07-17 22:50:09
-
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] nums = { 1, 3, 4, 5, 3, 8, 9, 6, 5, 2, 3, 1 };
int max = nums[0];
for (int i = 1; i < nums.length; i++) {
if (max < nums[i]) {
max = nums[i];
}
}
System.out.println(max);
}
2019-07-17 22:50:09