求数据结构程序,用c++编写的,{编写一个程序实现直接选择排序算法{6,8,7,9,0,1,3,2,4,5}

2024-12-23 00:00:33
推荐回答(1个)
回答1:

int a[10] = {6,8,7,9,0,1,3,2,4,5};
int *b;
int count = 0;
b = calloc(4*10,1);
while(count < 10)
{
int c = INT_MAX;
for(int i=1;i<10;i++)
{
if(a[i] < c)
{
c = a[i];
}
if(c == count)break;
}
b[count] = c;
count++;
}

结果:b = {0,1,2,3,4,5,6,7,8,9}