C Language classic algorithm bubble sort
#include "stdio.h"
int main(){
int a[10]={
1,3,2,5,9,7,6,8,4,0};
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (a[j]>a[j+1])
{
int b = a[j];
a[j]=a[j+1];
a[j+1]=b;
}
}
}
for (int i = 0; i < 10; i++)
{
printf("%d",a[i]);
}
return 0;
}
C Language classic algorithm function real bubble sort
#include "stdio.h"
void maopao(int a[])
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 10; j++)
{
if (a[j]>a[j+1])
{
int b = a[j+1];
a[j+1] = a[j];
a[j] = b;
}
}
}
}
int main()
{
int b[10];
for (int i = 0; i < 10; i++)
{
scanf("%d",&b[i]);
}
maopao(b);
for (int i = 0; i < 10; i++)
{
printf("%d",b[i]);
}
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(9):
if list1[b]>list1[b+1]:
c = list1[b]
list1[b] = list1[b+1]
list1[b+1] =c
for a in list1:
print(a)