Home > Back-end >  Using C language pointer array sort requires output sort results and sort the location of the former
Using C language pointer array sort requires output sort results and sort the location of the former

Time:12-12

Beginners don't quite understand how to use pointer array please help
Best can give some comments in the code thank you!

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 
#include

Int my_cmp (const void * a, const void * b)
{
Int * p=* (int * *) a;
Int * q=* (int) * * b;
Return * * p - q;
}

Int main (void)
{
Int * pa [10], I;

//array initialization
for(i=0; i<10; I++)
{
Pa [I]=(int *) malloc (sizeof (int));
The scanf (" % d ", pa [I]);
}

//quick sort
Tree (pa, 10, sizeof (int *), my_cmp);

//output sort the results
for(i=0; i<10; I++)
{
Printf (" % d % c, "* pa [I], I!=9? '\ t' : '\ n');
}

//handling, destruction of
for(i=0; i<10; I++)
{
[I] free (pa);
}

return 0;
}

CodePudding user response:

Reference:
 # include & lt; stdio.h> 
Int main (int arg c, char * argv [])
{
* pa int a [10], [10].
Int * temp;
Printf (" Input tan number: ");
for(int i=0; i<10; I++) {
The scanf (" % d ", & amp; A [I]);
Pa [I]=& amp; A, [I].
}

for(int i=0; i<10; I++) {
for(int j=0; j<10-1; J++) {
If (* pa [j] & gt; * pa [m + 1]) {
Temp=pa [j];
[j]=pa pa [j + 1);
Pa [j + 1)=temp;
}
}
}


for(int i=0; i<10; I++) {
Printf (" % 4 d, "* pa [I]);
}
printf("\n");
for(int i=0; i<10; I++) {
Printf (" % 4 d, "pa [I] - a);
}
printf("\n");

system("pause");
return 0;
}
  • Related