Table of Contents
This guide covers the qsort ()() function in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
The Qsort ()() Function in C
Qsort () function stands for Quick Sort, written based on Quick Sort algorithm.
Declaring the Function Qsort ()() in C
Below is the declaration for qsort () in C:
void qsort ( void * base , so - phan - tu , kich - co , int (* compar )( const void *, const void *))
Parameters
Base : This is the pointer to the first element of the array to be sorted.
So-phan-tu : This is the number of elements in the array pointed by the base pointer.
Kich-co : This is the size (in bytes) of each element in the array.
Compar : The function compares two elements.
Returns the Value
This function does not return any values.
For Example
The following C program illustrates the usage of qsort () in C:
#include #include int values [] = { 88 , 56 , 100 , 2 , 25 }; int cmpfunc ( const void * a , const void * b ) { return ( *( int *) a - *( int *) b ); } int main () { int n ; printf ( "Truoc khi sap xep, list co dang: n" ); for ( n = 0 ; n < 5 ; n ++ ) { printf ( "%d " , values [ n ]); } qsort ( values , 5 , sizeof ( int ), cmpfunc ); printf ( "nSau khi sap xep, list co dang: n" ); for ( n = 0 ; n < 5 ; n ++ ) { printf ( "%d " , values [ n ]); } return ( 0 ); } Compiling and running the above C program will result:
According to Tutorialspoint
Previous lesson: Function bsearch () in C
Next lesson: Function abs () in C
Frequently Asked Questions
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Was this article helpful?
Your feedback helps us improve.
Reader Comments 0
Sign in with email or Google to join the discussion.