Algorithm: Sets the number of records for the sorted sequence to n. I take the,..., n-1, and from All N-i+1 records (ri,ri+1,..., Rn) to find the smallest record of the sort code, exchange with the first record. The sequencing of the record sequence is completed after the n-1 is executed.
Compiler: VS2013
Code
#include "stdafx.h"
#include <stdlib.h>
function declaration
void Selectsort (int a[], int n); //Simple selection sort (small to large)
int main ()
{
int i,n,a[100];
printf ("Please enter the number of elements that need to be sorted:");
scanf_s ("%d", &n);
printf ("Randomly generated array is:");
for (i = 1; I <= n; i++)
{
A[i] = rand ()% 100 + 1;
printf ("%d", a[i]);
}
A[i] = ' + ';
printf ("\ n");
Selectsort (A,n);
}
Simple selection sort (small to large)
void Selectsort (int a[],int N)
{
int I=1, J, K,min;
for (min = a[1]; I <= n; i++)
{
K = i;
for (j = i; J <= N; j + +)
if (A[j] < a[k])
K = J;
if (k! = i)
{
min = a[k];
A[K] = A[i];
A[i] = min;
}
}
printf ("\ n Simple selection of results after sorting (from small to Large):");
for (i = 1; I <= n; i++)
printf ("%d", a[i]);
printf ("\ n");
}
Results
Simple selection and sorting of C language data structure