冒泡排序:
#include
#define SIZE 5
void bubble_sort(int a[], int n);
void bubble_sort(int a[], int n)
{
int i, j, temp;
for (j = 0; j < n - 1; j++)
for (i = 0; i < n - 1 - j; i++)
{
if(a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
int main()
{
int number[SIZE] = {95, 45, 15, 78};
int i;
bubble_sort(number, SIZE);
for (i = 0; i < SIZE; i++)
{
printf("%d", number[i]);
}
printf("\n");
}
选择排序函数:
void select_sort(int*a,int n)
{
register int i,j,min,t;
for(i=0;i
min=i;//查找最小值
for(j=i+1;j
min=j;//交换
if(min!=i)
{
t=a[min];
a[min]=a[i];
a[i]=t;
}
}
}
有啥问题还可以单独问哦