mplete the below code with function declaration which is void sort and argument array you required to use qsort function with standard library..  Please so as soon as

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Complete the below code with function declaration which is void sort and argument array you required to use qsort function with standard library.. 

Please so as soon as

 

In this task, you are required to implement a function that sorts elements of an int array in ascending order.
1. The function declaration is void sort(int *array, int size).
o argument array is the pointer of an int array which is composed of size elements.
o argument size is the number of elements in the array.
2. The function modifies the argument array so that its first element has the smallest value, and the last element has the largest value.
Although it is possible to solve this problem using, e.g., selection sort algorithm which swaps the smallest element in the remaining portion
of the array, you are required to use qsort function of the standard library, which is declared in stdlib.h. Please check the
documentation of qsort function.
In order to use qsort function, you are required to define a comparison function that has the following properties.
1. The function declaration is int compare_ascending(const void* p1, const void* p2); .
Hint
Since arguments are generic constant pointers, they should be casted to the type of the array before making the comparison.
2. The function returns,
i. a negative integer (e.g. -1) when the value pointed by p1 goes before the value pointed by p2.
ii. e if the values pointed by p1 and p2 are equal.
iii. a positive integer (e.g. 1) when the value pointed by p1 goes after the value pointed by p2.
Transcribed Image Text:In this task, you are required to implement a function that sorts elements of an int array in ascending order. 1. The function declaration is void sort(int *array, int size). o argument array is the pointer of an int array which is composed of size elements. o argument size is the number of elements in the array. 2. The function modifies the argument array so that its first element has the smallest value, and the last element has the largest value. Although it is possible to solve this problem using, e.g., selection sort algorithm which swaps the smallest element in the remaining portion of the array, you are required to use qsort function of the standard library, which is declared in stdlib.h. Please check the documentation of qsort function. In order to use qsort function, you are required to define a comparison function that has the following properties. 1. The function declaration is int compare_ascending(const void* p1, const void* p2); . Hint Since arguments are generic constant pointers, they should be casted to the type of the array before making the comparison. 2. The function returns, i. a negative integer (e.g. -1) when the value pointed by p1 goes before the value pointed by p2. ii. e if the values pointed by p1 and p2 are equal. iii. a positive integer (e.g. 1) when the value pointed by p1 goes after the value pointed by p2.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY