Skip to content

Instantly share code, notes, and snippets.

@poetries
Created April 29, 2016 15:12
Show Gist options
  • Save poetries/5dd4a27a261fdfd9da381024db5e244a to your computer and use it in GitHub Desktop.
Save poetries/5dd4a27a261fdfd9da381024db5e244a to your computer and use it in GitHub Desktop.
sort 直接选择排序
//直接选择排序
#include<stdio.h>
void sort(int *a,int len)
{
int i,j,min,t;
for(i = 0;i<len-1;++i)
{
for(min=i,j=i+1;j<len;++j)
{
if(a[min]>a[j])
min = j;
}
if(min!=i)
{
t = a[i];
a[i] = a[min];
a[min] = t;
}
}
}
void main()
{
int a[6] = {4,0,3,2,5,1};
sort(a,6);//a代表数组的首地址
for(int i=0;i<6;++i)
printf("%d\n",a[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment