C Language classical algorithm selection sorting
#include "stdio.h"
int main()
{
int a[10]={
3,1,2,8,9,5,7,4,0,6};
for (int i = 0; i < 9; i++)
{
for (int j = i+1; j < 10; j++)
{
if (a[i]>a[j])
{
int b = a[i];
a[i] = a[j];
a[j] = b;
}
}
}
for (int i = 0; i < 10; i++)
{
printf("%d",a[i]);
}
return 0;
}
C Language classic algorithm functions to achieve selective sorting
#include "stdio.h"
void xuanzhe(int a[])
{
for (int i = 0; i < 9; i++)
{
for (int j = i+1; j < 10; j++)
{
if (a[i]>a[j])
{
int b = a[i];
a[i]=a[j];
a[j]=b;
}
}
}
for (int i = 0; i < 10; i++)
{
printf("%d",a[i]);
}
}
int main()
{
int a[10];
for (int i = 0; i < 10; i++)
{
scanf("%d",&a[i]);
}
xuanzhe(a);
return 0;
}
Python Implement selection sorting
list1=[3,2,4,1,9,7,0,6,5,8]
for a in range(10):
for b in range(a+1,10):
if list1[a]>list1[b]:
c = list1[a]
list1[a] = list1[b]
list1[b] =c
for a in list1:
print(a)