How to use the C language to achieve a bubble sort

#include<stdio.h>
int main()
{
int a[5]={1,5,9,7,6};
int temp; 
// the length of the array; int size = sizeof (a) / sizeof (a [0]) 
for(int i=0;i<size;i++)
{
for(int j=0;j<size-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;

}
}
}
for(int i=0;i<size;i++)
{
printf("%d ",a[i]);
}
Published 15 original articles · won praise 39 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_37024565/article/details/77969441