package com;
/**
* 实现选择排序
* @author 小小王
*
*/
public class TestSelectSort {
//选择排序方法
public static void selectSort(int[] a){
int i = 0;
int j = 0;
int temp = 0;
int flag = 0;
int n = a.length;
for(i = 0; i < n; i++){
temp = a[i];
flag = i;
for(j = i+1; j < n; j++){
if(a[j] > temp){
temp = a[j];
flag = j;
}
}
if(flag != i){
a[flag] = a[i];
a[i] = temp;
}
}
}
public static void main(String[] args) {
int a[] = {4,6,2,4,8,5,2,9};
selectSort(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
/**
* 实现选择排序
* @author 小小王
*
*/
public class TestSelectSort {
//选择排序方法
public static void selectSort(int[] a){
int i = 0;
int j = 0;
int temp = 0;
int flag = 0;
int n = a.length;
for(i = 0; i < n; i++){
temp = a[i];
flag = i;
for(j = i+1; j < n; j++){
if(a[j] > temp){
temp = a[j];
flag = j;
}
}
if(flag != i){
a[flag] = a[i];
a[i] = temp;
}
}
}
public static void main(String[] args) {
int a[] = {4,6,2,4,8,5,2,9};
selectSort(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}