1.
Bubble sort: There are N number, to compare N-1 Wheel, the first round compares N-1 times. Each additional round, the number of times will be reduced one time, then the n-1-i; Select Sort method: Have N number, Comparison N-1 Times, the first round to find the minimum value, placed in the lowest subscript position, the second round to find the remaining minimum value, if the value is not in the subscript second small position, then put it in that position.
/*
Bubble sort (bubblesort) Explanation: Descending/Ascending. (compare two adjacent data)
Formula: Two-phase comparison, small front, outer circulation N-1 times, inner circulation n-1-i times.
*/
public class test3{
public static void Main (string[] args) {
--Define the number of groups
int[] arr = new int[]{7,2,10,9,45,3};
--Temporary variables
int temp = 0;
The outermost comparison is: the length of the array-1. n Number of wheels compared to N-1
for (int i=0;i<arr.length-1;i++) {
The number of comparisons per round is n-1-i; After the first round, the maximum value is found and the last, then the next comparison is less.
for (int j=0;j<arr.length-1-i;j++) {
--Comparison of two data
if (Arr[j]<arr[j+1]) {
int temp = Arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
}
}
}
for (int i=0;i<arr.length;i++) {
System.out.print (arr[i]+ "");
}
}
}
Java Array 3 (2015-8-27)