Ideas for reference:
Http://www.cnblogs.com/kkun/archive/2011/11/23/2260281.html
The code is as follows:
1 //171028 Select Sort. cpp: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <random>7 8 using namespacestd;9 Ten voidSelection_sort (unsignedintA[],intLen//sort in ascending order One { A intK =0; - intSwap =0; - for(inti =0; I < Len-1; i++)//How many times? the { -K =i; - for(intj = i +1; J < Len; J + +)//each time the smallest number is selected - { +K = (A[k] > A[j])? J:k;//if sorted in descending order, change here to A[k] < A[j] - } + //Exchange ASwap =A[i]; atA[i] =A[k]; -A[K] =swap; - } -cout <<"sequence of arrays after sorting:"; - for(inti =0; i < Len; i++) - { incout << A[i] <<ends; - } tocout <<Endl; + } - the intMain () * { $ /*default_random_engine E;Panax Notoginseng uniform_int_distribution<unsigned> U (0, +);*/ -Unsignedinttest[9] = {1,4,6,9,7,2,8,5,3 }; the /*for (int i = 0; i < i++) + { A Test[i] = u (e); the }*/ +cout <<"sequence of arrays before sorting:"; - for(auto c:test) $cout << C <<ends; $cout <<Endl; -Selection_sort (Test,sizeof(test)/sizeof(test[0])); - return 0; the}
Select Sort "Code"