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 key can be pressed repeatedly to decrease your brush size?

A. right arrow B. right bracket C. left arrow D. left bracket

Computer Science & Information Technology

Name three things make pat answers impossible when it comes to lighting

What will be an ideal response?

Computer Science & Information Technology

A metric is ___

a. When a router obtains a clear view of the routes in a network. b. A numeric measure assigned to routes for ranking the routes best to worst; the smaller the number, the better. c. A procedure in the protocol that enables routers to use any of the multiple data paths available from multiple routers to reach the destination. d. A procedure in the protocol that determines the best route.

Computer Science & Information Technology

Case 2Liz is the web designer for Alotta Cola, and she has been asked to spice up the company website.  Because the summer season is approaching, she decides to add some background images of bottles of Alotta Cola and various summer scenes. Why does she decide to use background images?

A. Tiled images take too long to download. B. They provide depth and visual interest to a page. C. It is easier than adding music and animation. D. She thinks that a background image will go well with the background color she has chosen.

Computer Science & Information Technology