Select sort directly select sort, select sort
Today, Dapeng learned how to directly select the sorting method in sorting.
Straight SelectSort is also a simple sorting method. Its basic idea is to first select the minimum value from R [0]-R [n-1, exchange with R [0], select the minimum value from R [1]-R [n-1] For the second time, and exchange with R [1 ,... A total of N-1 exchanges are used to obtain an ordered sequence of sorted codes in ascending order.
The Java implementation code is as follows:
Public classStraightSelectSort {
Public static voidMain (String [] args ){
//TODOAuto-generatedmethod stub
Int[] A = };
IntI, j, index;
System.Out. Print ("Before sorting :");
For(IntX: ){
System.Out. Print (x + ",");
}
For(I = 0; I <a. length; I ++ ){
Index = I;
For(J = I + 1; j <a. length; j ++ ){
If(A [j] <a [index])
Index = j;
If(I! = Index ){
IntTmp = a [I];
A [I] = a [index];
A [index] = tmp;
}
}
}
System.Out. Print ("sorted :");
For(IntX: ){
System.Out. Print (x + ",");
}
}
}
Regardless of the initial status of the sequence, n-I comparisons are required to select the maximum and minimum keyword records in the I-th sorting. Therefore, the total number of comparisons is n (n-1) /2 = O (n ^ 2 ).
What is the difference between simple selection sorting and Direct selection sorting?
It is called differently. In fact, the two are exactly the same.
Directly select sort C language (Supplement directly select sort)