Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1) Write a function that takes an array and its size as inputs, and then sorts the elements of the array in ascending order. For

image text in transcribed
image text in transcribed
Q1) Write a function that takes an array and its size as inputs, and then sorts the elements of the array in ascending order. For example, if the array contains the values (12,-3,5, 4,7), then the array sorted in ascending order will be (-3,4,5, 7, 12). In order to sort the array, you must use the following algorithm: (0) Initialize i = 0; (1) Starting at array index i, find the smallest value in the array at or after index i (i.e., any index greater than or equal to i within the proper array bounds). (2) Swap the smallest value found in the array with the value at index i; (3) Increment i by one; (4) If i is less than the array size, then repeat the process starting at step (1). You must use the following function prototype: void sort(int array, int size); Note: You must write your function prototype in a header file named Ilibsort.h and you must write your function definition in a source file named libsort.c. We are providing you the main source file sort.c, which you can use to test your function. Do n thing in sort.c ot change any- In the same libsort.c, write a function that calculates the median of the array. The me- dian is the "middle" number of a sorting array. If the array size is a even number, the median is the average of two middle numbers. If the array size is an odd number, the median will be equal to the value of the middle number. For example, the array with the even numbers, is given by 11,4,2,5,7,3). After sorting it, the array becomes (1,2,3, 4,5,7) and the median will be (3+4)/2 = 3.50. You must also add the following prototype to libsorth float find median(int arrayD, int size); To compile your code, remember that you must compile both sort.c and libsort.e but not libsort.h. In other words, run 'gcc sort.c libsort.c' Hint: To determine wether a number is a even number or odd number, you can use the modulooperator %. If you type n%2 The number n is divided by 2 and it will return t

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

Step: 3

blur-text-image

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago