Home > Back-end >  The question about the two dimensional array sort
The question about the two dimensional array sort

Time:11-30


I want to ask a question,
To define a 2 d array
A [4] [4]={
{1.2.6.3}.
{2.6.3.14}.
{1.3.4.8}.
{8.5.3.6}
}
Such a two dimensional array sort, not to convert the array into a one-dimensional array (not change has not been sorted array) will sort a two-dimensional array of output,
Requirements:
1. All sorting,
2. Only the fourth column sorting,
3. Only the diagonal sorting,
(this is three questions, respectively)
How should be described using c + + or c??
If you have time to give me answers about

CodePudding user response:

Array, which is continuous a memory address space, how to operate, free play,
To get a full full sorting, only supplies the reference: second, or third, you can refer to the shell sort,
 # include & lt; Stdio. H> 
#include

Int my_cmp (const void * I, const void * j)
{
Int * a=(int *) I;
J int * b=(int *);
Return (* - * b);
}

Int main (void)
{
Int a [4] [4]={{1,2,6,3}, {2,6,3,14}, {1,3,4,8}, {8,5,3,6}};

Tree (a, 4 * 4, sizeof (int), my_cmp);

for(int i=0; i<4. I++)
{
for(int j=0; J<4. J++)
{
Printf (" % d \ t ", a [I] [j]);
}
printf("\n");
}

return 0;
}

CodePudding user response:

reference 1st floor ctrigger response:
array, is continuous a memory address space, how to operate, free play,
To get a full full sorting, only supplies the reference: second, or third, you can refer to the shell sort,
 # include & lt; Stdio. H> 
#include

Int my_cmp (const void * I, const void * j)
{
Int * a=(int *) I;
J int * b=(int *);
Return (* - * b);
}

Int main (void)
{
Int a [4] [4]={{1,2,6,3}, {2,6,3,14}, {1,3,4,8}, {8,5,3,6}};

Tree (a, 4 * 4, sizeof (int), my_cmp);

for(int i=0; i<4. I++)
{
for(int j=0; J<4. J++)
{
Printf (" % d \ t ", a [I] [j]);
}
printf("\n");
}

return 0;
}

If it's not a pointer, can only use for?
  • Related