The basic idea of simply selecting a sort (simple selection sort):
For the first time, select the smallest of all the array elements in the first position, the second one from the remaining n-1 elements to the second position, and so on, until one element is left and placed in the last position.
Basic steps:
(1) First through n-1 comparison, from the n array of elements to find the smallest, it and a[0] Exchange-The 1th trip to select the order, the smallest number of results are placed in the a[0] position.
(2) Again through n-2 comparison, from the remaining n-1 number of elements to find the minor, it and a[1] Exchange-The second trip to select the order, the results of the small place in the a[1] position.
(3) Repeat the above process, after a total of n-1 order, sort the end.
Code:
#include <iostream>using namespacestd;intMain () {inta[8]={ +, -, A, -, -, -, the, $}; intk,t; for(intI=0;i<7; i++) {k=i; for(intj=i+1;j<8; j + +) if(a[j]<A[k]) k=J; if(k! =i) {t=A[k]; A[K]=A[i]; A[i]=T; } } for(intI=0;i<8; i++) cout<<a[i]<<Endl;}
C + + implementation of simple selection sorting