Question
qsort is a function used for sorting arrays of any type. In order for this to work a comparator function must be given that defines
qsort is a function used for sorting arrays of any type. In order for this to work a comparator function must be given that defines what makes a value greater than, less than or equal to another value. The prototype for qsort is as follows:
void qsort ( void * base, size_t num, size_t size,
int ( * comparator ) ( const void *, const void * ) );
Parameters represent the starting location, number of elements, size of an element, and comparator function.
Suppose that you have an array of struct x_struct called, say, xarray[50]. You wish to sort the array using qsort. Naturally, you will need some type of comparison function to decide how two elements are related; either the first is less than the second, equal to the second, or greater than the second. Unfortunately you cannot just tell qsort to use memcmp as the comparison function. Why not? Give a syntactical reason and a logical reason.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started