发布网友 发布时间:2022-05-10 20:43
共1个回答
热心网友 时间:2023-10-30 06:14
#include <stdio.h>追答#include
#define MAX 10
#define SWAP(x,y) {int t;t = x;x = y;y = t;}
insert_sort(int a[],int n)
{
int i,j,temp;
for(i = 1;i = 0 && temp > a[j];j--)
a[j+1] = a[j];
a[j+1] = temp;
}
}
void select_sort(int a[],int n)
{
int i,j;
for( i=0; i< n-1; i++)
{
int pos = i;
for( j=i+1; j<n; j++)
{
if (a[j] < a[pos]) pos = j;
}
if(pos!=i)
SWAP(a[pos], a[i]);
}
}
int main(void)
{
int i;
int a[MAX] = {0};
for(i = 0;i<MAX;i++)
scanf("%d",&a[i]);
printf("排序前:");
for(i = 0; i < MAX; i++) {
printf("%d ",a[i]);
}
insert_sort(a,MAX);
//select_sort(a,MAX);
printf("\n排序后:");
for(i = 0; i < MAX; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
稍微改一下么
这点还不知道么