#include <stdio.h>
//打印
void show(int *a,int length)
{
int i,j;
for(i=0;i<length;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
printf("------show end--------------------\n");
}
//冒泡排序 降序
void maopao_sort(int *a,int length)
{
int i,j,temp;
for(i=0;i<length-1;i++)
{
for(j=0;j<length-i-1;j++)
{
if(a[j] < a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("------maopao_sert end--------------------\n");
}
//选择排序 升序
void choice_sort(int *a,int length)
{
int i,j,temp,subscript;
for(i=0;i<length-1;i++)
{
subscript=i;
for(j=i+1;j<length;j++)
{
if(a[j] < a[subscript])
{
subscript=j;
}
}
if(i!=subscript)
{
temp=a[i];
a[i]=a[subscript];
a[subscript]=temp;
}
}
printf("------choice_sert end--------------------\n");
}
void main()
{
int a[]={1,23,34,45,576,687,762,34,23,2,43,65,76,66};
int length;
length=sizeof(a)/sizeof(a[0]);
show(a,length);
maopao_sort(a,length);
show(a,length);
choice_sort(a,length);
show(a,length);
}
06-13
1385
08-20
224
08-16
534
07-12