qsort problem
-
can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)
-
can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)
int MySort( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return *(char*)arg1 - *(char*)arg2;
}void main()
{
char sText[10];strcpy(sText, "ASDFGHJKL");
qsort(sText, strlen(sText), sizeof(char), MySort);printf(sText);
printf("\n");
}Maxwell Chen People say "No news is good news". Then, no bug is good bug!?
-
can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)
// Next time just use msdn.X| Example /* QSORT.C: This program reads the command-line * parameters and uses qsort to sort them. It * then displays the sorted arguments. */ #include #include #include int compare( const void *arg1, const void *arg2 ); void main( int argc, char **argv ) { int i; /* Eliminate argv[0] from sort: */ argv++; argc--; /* Sort remaining args using Quicksort algorithm: */ qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /* Output sorted list: */ for( i = 0; i < argc; ++i ) printf( "%s ", argv[i] ); printf( "\n" ); } int compare( const void *arg1, const void *arg2 ) { /* Compare all of both strings: */ return _stricmp( * ( char** ) arg1, * ( char** ) arg2 ); } Output [C:\code]qsort every good boy deserves favor boy deserves every favor good X| X| X| X| X| X| X| Aizik Yair Software Engineer
-
// Next time just use msdn.X| Example /* QSORT.C: This program reads the command-line * parameters and uses qsort to sort them. It * then displays the sorted arguments. */ #include #include #include int compare( const void *arg1, const void *arg2 ); void main( int argc, char **argv ) { int i; /* Eliminate argv[0] from sort: */ argv++; argc--; /* Sort remaining args using Quicksort algorithm: */ qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /* Output sorted list: */ for( i = 0; i < argc; ++i ) printf( "%s ", argv[i] ); printf( "\n" ); } int compare( const void *arg1, const void *arg2 ) { /* Compare all of both strings: */ return _stricmp( * ( char** ) arg1, * ( char** ) arg2 ); } Output [C:\code]qsort every good boy deserves favor boy deserves every favor good X| X| X| X| X| X| X| Aizik Yair Software Engineer
-
thank you very much for you guys help. i really appreciate it. i dont have a MSDN library so i couldnt do this problem. thank you very much again. Thank you very much, John :-D Aloha from Hawaii :-)
John Cruz wrote: i dont have a MSDN library Have you seen http://msdn.microsoft.com/library ? Kind regards to Hawaii.