Video parsing https://edu.csdn.net/course/play/7813
When soldiers queue in a TV series, they are arranged in the order of tall and short, and the taller and taller are compared by 22.
Bubble Sort:
The basic idea is to repeat the order of the entire array, compare two elements at a time (22 sorted), and then swap them if they do not match, repeating this until the number of numbers is no longer needed (the end condition).
Because it is like a bubble, light bubbles will float up, in the process of continuous floating, 22 exchange process occurred, so called bubble sort.
/**
* *
* @author Zhang Chenguang * * * *
/public class Sortdemo {
//Common static member variable publicly
-static int[]arr={ 5,2,6,7,3};
public static int[] Sort (int[]arr) {
int n=arr.length;
int temp;
for (int i=0;i<n;i++) {for
(int j=0;j<n-1;j++) {
if (arr[j]>arr[j+1]) {
//exchange
TEMP=ARR[J] ;
ARR[J]=ARR[J+1];
Arr[j+1]=temp
}
}} return arr;
}
/**
* Insert sort
/public static void Insertsort () {
}
/**
* sequence output array element;
*/public
static void PrintArray (int []arr) {for
(int num:arr) {
System.out.print (num+ "\ t");
}
System.out.println ();
}
/**
* Main method */public
static void Main (string[] args) {
sortdemo.sort (arr);
Sortdemo.printarray (arr);
}
The mnemonic method of coping with interview sequencing:
n numbers to sort,
22 relatively small forward;
Outer loop n-1,
inner layer circulation n-1-9;