5. From a user point of view the following code snippets give the same results.
ID: 3562549 • Letter: 5
Question
5. From a user point of view the following code snippets give the same results. What are the names given to the two different methods and which C++ standards, historically, introduced the methods.
(a) int numbers[10];
cout << "Enter ten integers: ";
for (int i = 0; i < 10; i++)
{
cin >> numbers[i];
}
// Sorting the array
sort( numbers, &numbers[10], [ ](int x, int y){ return x < y; } );
(b) int intcompare(const void *p1, const void *p2)
{
int i = *((int *)p1);
int j = *((int *)p2);
return (i < j) ;
}
.
.
int numbers[10];
cout << "Enter ten integers: ";
for (int i = 0; i < 10; i++)
{
cin >> numbers[i];
}
qsort((void *)numbers, 10, sizeof (int), intcompare);
Explanation / Answer
The two methods gives the Sorted Array as the output.
The first method is a Generic call to a Sorting method.
The comparision code is completely specified in the definition itself.
Whereas the second method is a specific call to Quick Sort method.
The comparision method definition and implementation is separated.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.