Write functions Sort and Largest in addition to function main and call Sort within main.

CEG 2170L -05 Lab 4:

Sorting a list of numbers

October 02, 2017

In this exercise we will learn how to sort a list of numbers in descending order (from the largest to the smallest). Suppose an array (a list) of N numbers is available. We want to order the numbers from the largest to the smallest. It is assumed that N ≤ 100.

Function Sort: This function receives a 1-D integer array A of size N and sorts the numbers in descending order.

For k = 0 to N-2 do the following:
Call function Largest to find the largest number in the list from A[k] to A[N-1]. Suppose j is the index of the largest number in the list from A[k] to A[N-1].
Switch A[k] and A[j].
Function Largest: This function receives an array A, its size N, and two indices m and n. It then returns the index of the largest number in the list from A[m] to A[n]. It is assumed that n > m, m >= 0 and n < N.

Let L = A[m] and j = m.
For k = m+1 to n do the following:
If A[k] > L, let L = A[k] and j = k;
Return j.

DESCRIPTION:

Prompt the user for N, then for N integers.
Sort numbers in the list in descending order by calling function Sort.
Whenever there is a change in the list, print the list. For example, when array A contains, {1, 4, -9, 3, 2}, your program should print:
{-9, 4, 1, 3, 2}, {-9, 1, 4, 3, 2}, …… , {-9, 1, 2, 3, 4}

REQUIREMENT:

Write functions Sort and Largest in addition to function main and call Sort within main.
SUBMISSION:

Name your program LastName_FirstName_Lab4.c and upload it to the Dropbox under Lab Assignment 4 by 4:30 pm today.

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"FIRST15"

Order Now