/**任务目标 矩阵排序 **
题目:给你特定的矩阵(整形) 进行排序 注意 不能将二维数组 变成一维
排序的方法 放在函数里
然后输出排序后结果
举例 说明 :
给定矩阵
a[10][10]={
{61,29,63,64,3,66,67,68,69,70},
{11,12,13,14,56,16,17,18,19,20},
{91,92,93,79,78,96,42,98,51,100},
{40,82,48,84,85,86,5,43,89,90},
{31,59,33,34,35,36,55,38,39,81},
{21,22,23,24,25,26,27,28,62,30},
{99,52,41,54,37,15,57,58,32,60},
{1,2,65,4,87,6,7,8,9,10},
{71,72,73,74,75,76,77,95,94,80},
{53,97,88,44,45,46,47,83,49,50},
}
排序后
a[10][10]={
{1,2,3,4,5,6,7,8,9,10},
{11,12,13,14,15,16,17,18,19,20},
{21,22,23,24,25,26,27,28,29,30},
{31,32,33,34,35,36,37,38,39,40},
{41,42,43,44,45,46,47,48,49,50},
{51,52,53,54,55,56,57,58,59,60},
{61,62,63,64,65,66,67,68,69,70},
{71,72,73,74,75,76,77,78,79,80},
{81,82,83,84,85,86,87,88,89,90},
{91,92,93,94,95,96,97,98,99,100}
}
*/
#include<stdio.h>
void changeLine(int (*a)[10],int j)//行变换 每一行进行冒泡排序
{
int i;//数组坐标
//int j;//数组坐标
int k;//冒泡循环
int t;//中间值
i=0;
k=0;
t=0;
for(k=0;k<9;k++)
{
for(i=0;i<9-k;i++)
{
if(a[j][i]>a[j][i+1])
{
t=a[j][i+1];
a[j][i+1]=a[j][i];
a[j][i]=t;
}
}
}
}
void changeRow(int (*a)[10],int i)//列变换 每一列进行冒泡排序
{
//int i;//数组坐标
int j;//数组坐标
int k;//冒泡循环
int t;//中间值
k=0;
t=0;
for(k=0;k<9;k++)
{
for(j=0;j<9-k;j++)
{
if(a[j][i]>a[j+1][i])
{
t=a[j+1][i];
a[j+1][i]=a[j][i];
a[j][i]=t;
}
}
}
}
void changeNumber(int (*a)[10],int j)//每一行末尾与下一行进行变换
{
int i,t;
i=0;
t=0;
if(j!=9)
{
if(a[j][9]>a[j+1][0])
{
t=a[j][9];
a[j][9]=a[j+1][0];
a[j+1][0]=t;
}
}
}
int main()
{
int (*p)[10];
int a[][10]=
{
{61,29,63,64,3,66,67,68,69,70},
{11,12,13,14,56,16,17,18,19,20},
{91,92,93,79,78,96,42,98,51,100},
{40,82,48,84,85,86,5,43,89,90},
{31,59,33,34,35,36,55,38,39,81},
{21,22,23,24,25,26,27,28,62,30},
{99,52,41,54,37,15,57,58,32,60},
{1,2,65,4,87,6,7,8,9,10},
{71,72,73,74,75,76,77,95,94,80},
{53,97,88,44,45,46,47,83,49,50},
};
p=a;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
for(int o=0;o<12;o++)
{
for(int m=0;m<10;m++)
{
changeLine(p,m);
changeRow(p,m);
changeNumber(p,m);
}
}
printf("排序后\n");
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}