Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to sort 10 integers by selection method?
How to sort 10 integers by selection method?
Selective sorting is a simple and easy-to-implement data sorting algorithm. Take plastic array elements as an example, there are arrays A[ 10], namely A[0], A[ 1], …, A[8] and A[9] (assuming their elements are different from each other). You need to sort its elements so that they increase in order.

First, scan from one direction based on one element, for example, from left to right based on A[0].

Next, find the smallest element from A[0], …, A[9] and exchange it with A[0].

Then move the reference position to the right by one position and repeat the above actions. For example, based on A[ 1], find the minimum value of A[ 1]~A[9] and exchange it with A[ 1].

Until the benchmark position moves to the last element of the array, the sorting ends (at this time, all elements on the left of the benchmark increase in turn, and the benchmark is the last element, and the sorting is completed).

Master ()

Int array [10]; ?

//Initialize the array!

int i,j,k,temp?

for(I = 0; I< 10- 1; i++) {

k = I; ?

for(j = I+ 1; j & lt 10; j++)

if(array[j]& lt; array[k])k = " j "; = " " temp = " array[k]; Array[k]= array; array = temp"}="" }