45. Sort

/*
n[10]={5,25,84,64,46,82,89,99,76,36};


Reference number number comparison number number
1st round: 0 1-9 after the smallest in the 0th
round: 1 2-9 after the 2nd smallest in the 1st
round 3: 2 3-9
in the 4th round : 3 4-9
Round 5: 4 5-9
Round 6: 5 6-9
Round 7: 6 7-9
Round 8: 7 8-9
Round 9: 8 9-9
i i+1- 9
10 numbers take 9 rounds
*/
#include "stdio.h"
void main()
{
int n[10]={25,61,84,46,36,25,89,99,76,5},t ;
int i,j;

printf("The array is as follows before sorting:\n");
for(i=0;i<=9;i++)
printf("%3d",n[i]);
printf("\n ");

//sort
for(i=0;i<=8;i++)//rounds (number range of reference numbers)
{
for(j=i+1;j<=9;j++)//every 1 Number of comparison rounds (number range of comparison numbers)
{
if(n[i]<n[j])//Comparison
{
//Transposition
t=n[i];
n[i]=n[j];
n[j]=t;
}
}
}

printf("The array is sorted as follows:\n");
for(i=0;i<=9;i++)
printf("%3d",n[i]);
printf ("\n");
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325817703&siteId=291194637