功能:排列一个m行n列 大小的数组
输入: int * pArray 指向数组第一个元素的指针,m为行数, n为列数 ,请按第i列排列
输出:按第i列排序完成后的数组放到入参指定的地址中 (i的取值范围 1 - n)
返回:
功能:排列一个m行n列 大小的数组
输入: int * pArray 指向数组第一个元素的指针,m为行数, n为列数 ,请按第i列排列
输出:按第i列排序完成后的数组放到入参指定的地址中 (i的取值范围 1 - n)
整理自: 点击打开链接
输入: int * pArray 指向数组第一个元素的指针,m为行数, n为列数 ,请按第i列排列
输出:按第i列排序完成后的数组放到入参指定的地址中 (i的取值范围 1 - n)
返回:
功能:排列一个m行n列 大小的数组
输入: int * pArray 指向数组第一个元素的指针,m为行数, n为列数 ,请按第i列排列
输出:按第i列排序完成后的数组放到入参指定的地址中 (i的取值范围 1 - n)
返回:空
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
</pre><pre name="code" class="cpp">void RangeArray(int * pArray,unsigned int m, unsigned int n,unsigned int i)
{
if( pArray == NULL || m<0 || n<0 || i>n )
return;
int * tempArray=new int[n];
//从最后一列开始排序,排序到指定列
for(unsigned int column=n-1;column>=i-1;column--)
{
//对每一列进行排序,冒泡排序的变形
for(unsigned int iIn=0;iIn<m-1;iIn++)
{
for(unsigned int j=0;j<m-iIn-1;j++)
{
if (*(pArray+(j+1)*n+column) < *(pArray+(j)*n+column))
{
memcpy(tempArray,pArray+j*n,n*sizeof(int));
memcpy(pArray+j*n,pArray+(j+1)*n,n*sizeof(int));
memcpy(pArray+(j+1)*n,tempArray,n*sizeof(int));
}
}
}
if(column==0)
{break;}
}
}
int main()
{
int array[] =
{
1,3,2,
2,2,4,
2,3,1,
1,3,1
};
int m = 4;
int n = 3;
int i = 2;
RangeArray(array,m,n,i);
return 0;
}
整理自: 点击打开链接