Write the selection sort algorithm for an array of int in C++. You are to assume that there are predefined functions swapValues and indexOfSmallest, that is do not write these functions. However, you must write declarations with pre and post conditions for these functions.

What will be an ideal response?


```
void swapValues(int & v1, int& v2);
>>>Attach & to first int for consistency
//precondition: args have been initialized
//postcondition: v1post = v2pre, v2post = v1pre.

int indexOfSmallest(const int a[], int start, int numberUsed);
//Precondition: startIndex is a legal index for array a
// args are initialized.
//Postcondition: index value such that a[i] is the
//smallest of values in the array.

void sort(int a[], int numberUsed)
{
int indexOfNextSmallest;
for(int index=0; index < numberUsed-1; index++)
{// place next smallest in a[index]
indexOfNextSmallest =
indexOfSmallest(a, index, numberUsed);
swapValues(a[index], a[indexOfNextSmallest]);
//Assert:[0]<=a[1]<=...<=a[index] are the smallest
//of the original array elements. The rest of the
//elements are at index values beyond index.
}
}
```

Computer Science & Information Technology

You might also like to view...

What is NOT an advantage of an enum class over a standard enum?

a. Doesn’t map to an integer b. Values are not global in scope c. Occupies less memory

Computer Science & Information Technology

Critical Thinking QuestionsCase 3-1You know that your colleague Enrique does a masterful job maintaining his contacts in Outlook so when you are looking for advice on print styles, he is the person to whom you turn.You would like a printout of your own contact list with a page for each contact, so you can write some notes on them. Which print style does Enrique tell you to use? a. Single Pagec. Phone Directoryb. Memod. Card

What will be an ideal response?

Computer Science & Information Technology

Formulas created using the point-and-click method contain ____ references.

A. absolute B. mixed C. relative D. relational

Computer Science & Information Technology

How much data can a SATA revision 3.0 drive transfer per second?

a. 1.5 Gb/s b. 3.0 Gb/s c. 4.5 Gb/s d. 6.0 Gb/s e. 16.0 Gb/s

Computer Science & Information Technology