Skip to content

Instantly share code, notes, and snippets.

@poetries
Last active April 29, 2016 15:04
Show Gist options
  • Save poetries/2b5a68d45ce02bba3fd1175f1f279cb6 to your computer and use it in GitHub Desktop.
Save poetries/2b5a68d45ce02bba3fd1175f1f279cb6 to your computer and use it in GitHub Desktop.
sort
#include<stdio.h>
void sort(int *a,int len)
{
int i,j,t;
for( i = 0;i<len-1;++i)
{
for(j = i+1;j<len;++j)//或者 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;
}
}
}
}
void main()
{
int a[6] = {10,2,8,-8,11,0};
int i = 0;
sort(a,6);
for(i = 0; i<6;++i)
{
printf("%d ",a[i]);
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment