Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

Students also viewed these Databases questions

Question

Evaluate :(e)-(4) - (A)- -() 9. 9. 3 lim

Answered: 1 week ago