Problems: In this lab, you are to write solutions to the following two problems. In each case, turn in your solutions utilizing the format for submitting assignments.
void partition (int a[], int left, int right, int *middle)which rearranges elements those within the a array with indices between left and right, so that
Thus, the array segment a[left] ... a[right] is rearranged as required, to give a new arrangement of values a[left] ... a[(*middle)] ... a[right], where all array elements before position *middle have values <= a[(*middle)] and where a[(*middle)] is less than or equal to all array elements after position *middle.
Include your partition procedure in an appropriate test program, so that you can adequately check the correctness of your code.
Discussion: Work within partition should be done with a single pass through the elements a[left] ... a[right], as follows.
Write a procedure
void quicksort (int a[], int n)that uses the partition procedure and sorts the array a[0], ..., a[n-1] using the quicksort algorithm. Since this quicksort is to be a general sorting procedure for any array, the integer n is used to indicate the size of the array.
As in the previous problem, you should include your quicksort procedure in an appropriate test program, so that you can adequately check the correctness of your code.
Problem:
void select (int a[], int k)that uses the above algorithm and procedure partition to find the kth smallest element in an array a.
void median (int a[], int n)that uses the above algorithm and procedure partition to find the median element in an array a, where n is the size of the array.
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/213.fa98/lab1.html