62,634
社区成员




class SelectSort
public static void main(String args[]) {
int vec[] = new int[] { 37, 47, 23, -5, 19, 56 };
int temp;
for (int i = 0; i < vec.length; i++) {
for (int j = i; j < vec.length; j++) {
if (vec[j] > vec[i]) {
temp = vec[i];
vec[i] = vec[j];
vec[j] = temp;
}
}
}
class Test{
static int a[]={5,4,8,9,7,2,6,5};
public static void main( String[] args ){
System.out.println("=====升序======");
for(int i=1;i<a.length;i++){
int temp=a[i];
int j=i;
for(;(j>0)&&(temp<a[j-1]);j--){
a[j]=a[j-1];
}
a[j]=temp;
}
for(int n:a){
System.out.println(n);
}
System.out.println("=====降序======");
for(int i=1;i<a.length;i++){
int temp=a[i];
int j=i;
for(;(j>0)&&(temp>a[j-1]);j--){
a[j]=a[j-1];
}
a[j]=temp;
}
for(int n:a){
System.out.println(n);
}
}
}
public class SortTest {
public static void main(String[] args) {
int a[] = { 5, 4, 8, 9, 7, 2, 6, 5, 10 };
int[] b = selectMaxToMinSort(a);
for (int value : b) {
System.out.print(value + " ");
}
}
public static int[] selectMinToMaxSort(int[] input) {
for (int i = 0; i < input.length; i++) {
int temp = 9999;
int index = 0;
for (int j = i; j < input.length; j++) {
if (temp > input[j]) {
temp = input[j];
index = j;
}
}
if (index != 0) {
int t = input[index];
input[index] = input[i];
input[i] = t;
}
}
return input;
}
public static int[] selectMaxToMinSort(int[] input) {
for (int i = 0; i < input.length; i++) {
int temp = -9999;
int index = 0;
for (int j = i; j < input.length; j++) {
if (temp < input[j]) {
temp = input[j];
index = j;
}
}
if (index != 0) {
int t = input[index];
input[index] = input[i];
input[i] = t;
}
}
return input;
}
}