1. Bubble Sorting
1. Bubble Sorting vertically sorts the sorted record array R [1. N]. Each record R [I] is considered as a bubble with the weight of R [I]. Key. According to the principle that a Light Bubble cannot be under a heavy bubble, scan the array R from the bottom up: any light bubble that scans for a violation of this principle, so that it is "floating" (bubble name ). This is repeated until the last two bubbles are light and heavy. The following is an example of bubble-down.
class program {// // bubble sort /// // Public void sort (INT [] numarr) {int tmpnum; For (INT I = 0; I
numarr [J + 1]) {tmpnum = numarr [J]; numarr [J] = numarr [J + 1]; numarr [J + 1] = tmpnum ;}}} static void main (string [] ARGs) {int [] arr = new int [] {,}; program P = new program (); p. sort (ARR); For (int K = 0; k
2. selection sort)
The basic idea of sorting is to select the records with the smallest keyword from the records to be sorted, and put them at the end of the sorted sub-files until all the records are sorted.
/// <Summary> /// the basic idea of selection sort is to select the record with the smallest keyword from the record to be sorted, /// the sequence is placed at the end of the sorted subfile until all records are sorted. /// </Summary> /// <Param name = "numarr"> </param> Public void selectionsort (INT [] numarr) {int min, tmpnum; for (INT I = 0; I <numarr. length-1; I ++) {min = I; for (Int J = I + 1; j <numarr. length; j ++) {If (numarr [J] <numarr [Min]) {min = J ;}} tmpnum = numarr [I]; numarr [I] = numarr [Min]; numarr [Min] = tmpnum;} static void main (string [] ARGs) {int [] arr = new int [] {,}; program P = new program (); p. selectionsort (ARR); For (int K = 0; k <arr. length; k ++) {console. write ("{0}", arr [k]) ;}}