求各位大神帮忙.........
本人菜鸟.....昨晚做到现在还搞不定.......求给位大神帮忙......../*把矩阵一重新排列成矩阵二
2 5 15 10 2 9 10 24
13 24 3 6 3 7 11 16
9 16 7 11 5 6 13 15
*/
#include <stdio.h>
void sorting(int* array, int length);
int main(void)
{
int array[] = {2, 5, 15, 10, 13, 24, 3, 6, 9, 16, 7, 11};
int i;
printf("原矩阵:\n");
for(i = 0; i < 12; i++)
{
printf("%5d", array[i]);
if(i == 3 || i == 7 || i == 11)
{
printf("\n");
}
}
sorting(array, 12);
printf("排序后:\n");
for(i = 0; i < 12; i++)
{
printf("%5d", array[i]);
if(i == 3 || i == 7 || i == 11)
{
printf("\n");
}
}
return 0;
}
void sorting(int* array, int length)
{
int i, j;
int count = 0, min, temp, current;
current = array[0];
for(i = 0; i < length; i++)
{
switch(i)
{
case 1: min = 4; break;
case 2: min = 8; break;
case 3: min = 9; break;
case 4: min = 5; break;
case 5: min = 1; break;
case 6: min = 2; break;
case 7: min = 6; break;
case 8: min = 10; break;
case 9: min = 11; break;
case 10: min = 7; break;
case 11: min = 3; break;
default: min = 0;break;
}
for(j = i+1; j < length; j++)
{
if(array[j] < current)
{
continue;
}
else if(array[min] > array[j])
{
temp = array[i];
array[min] = array[j];
array[j] = array[min];
}
}
count++;
if(count == length)
{
break;
}
i = i-1;
current = array[min];
}
}
.......不知道怎么错的....求改正.....