C language bubble sort code
- 2020-04-01 21:33:02
- OfStack
Always write always in the wrong, the interview also forget
Learning is such a process, warm to know the new, hope to remember
It's ok to forget
It is good to review
// there are many ways to sort, from small to large
#include <stdio.h>
void sort(int *a,int len)
{int i=0;
int j;
int t;
for(i=0;i<len;i++)
{
for(j=0;j<len-i-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
int main(int argc, char *argv[])
{
int a[10]={
-999,2,3,77,12,88,0,-8,99,100
};
int i=0;
sort(a,10);
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
return 0;
}