1#include <stdio.h>2#include <stdlib.h>3 voidSelectsort (int*a,intn);//pre-declaring the function to be called4 intMainvoid)5 {6 intK;7 intx[Ten]={2,4,6,8,0,1,3,5,7,9};8 for(k=0;k<Ten; k++)9printf"%d", X[k]);Tenprintf"\ n"); OneSelectsort (x,Ten); A for(k=0;k<Ten; k++) -printf"%d", X[k]); -printf"\ n"); theSystem"Pause"); - - return 0; - } + - voidSelectsort (int*a,intN//array elements are pointers, number of arrays + { A intI,j,t;//integer variable at intMin//minimum value, index number - for(i=0; i<n-1; i++)//n-1 times Scan - { -Min=i;//first Element (minimum) before each scan - for(j=i+1; j<n;j++)//The second scan finds the minimum value and swaps - { in if(a[j]<A[min]) -min=J; to + } -T=a[i];//Temp Variable theA[i]=a[min];// *a[min]=T; $ }Panax Notoginseng -}
Choose the basic idea of sorting: each trip (such as Nth trip) in the back n-i+1 (i=1,2,..., n-1) to be sorted by the element of the lowest keyword, as the first element of the ordered subsequence, until the first n-1 to finish, to sort the elements only one left, there is no need to select.
Selection of algorithms and data structures (C language)