1. Bubble sort
(1) Principle: Multi-pass comparison, each pair of adjacent data through the constant judgment and exchange of the largest data placed in the last unsorted sequence, like a large bubble constantly upward floating
(2) Complexity of Time:
(3) Algorithm Stability: stable
(4) Code implementation:
Public void sort (int[] array) { int size=array.length; for (int i=1;i<size;i++) { for (int j=0;j<size-i;j++) { if(Array[j] >array[j+1]) { swap (array,j,j+1); }}}
2. Insert Sort
(1) Principle: Each step of a record to be sorted, according to the size of its key code value inserted in the previously sorted file in the appropriate position, until all is inserted.
(2) Complexity of Time:
(3) Algorithm Stability: stable
(4) Code implementation:
Public voidSortint[] Array) { intSize=Array.Length; for(inti=1;i<size;i++) { inttemp=Array[i]; intJ=i-1; while(j>=0&&temp<Array[j]) {Array[j+1]=Array[j]; J--; } array[j+1]=temp; } } Public voidBinarysort (int[] array)//binary Insert {intSize=Array.Length; for(inti=1;i<size;i++) { inttemp=Array[i]; intLow=0; intHigh=i-1; while(low<=High ) { intMid= (Low+high)/2; if(temp<Array[mid]) { High=mid-1; } Else{ Low=mid+1; } } for(intj=i-1;j>=low;j--) {array[j+1]=Array[j]; } Array[low]=temp; } }
3. Select sort
(1) Principle: each time from the data to be sorted to select the smallest element, stored in the starting position of the unordered sequence, until all the data elements to be sorted out
(2) Complexity of Time:
(3) Algorithm Stability: unstable
(4) Code implementation:
Public voidSortint[] Array) { intSize=Array.Length; for(inti=0;i<size;i++) { intmin=i; for(intj=i+1;j<size;j++) { if(array[min]>Array[j]) {min=J; } } if(min!=i) {swap (array,min,i); } } }
Sort (1)--bubbling, inserting, selecting