Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 2 - Challenge Work - Page 90: 2

Answer

$\bullet$ Get value of $n$ as size of the list $\bullet$ Get elements of list: $N_{1}, N_{2}, \ldots N_{n}$ $\bullet$ Set value of $i$ to $n$ $\bullet$ While $(i>1)$ do $\bullet\quad$ Set the value of Store to value of $N_{i}$ $\bullet\quad$ Set the value of largest to $N_{1}$ $\bullet\quad$ Set the value of location to 1 $\bullet\quad$ Set the value of $j$ to 2 $\bullet\quad$ While $j$ largest then $\bullet\quad\quad\quad$ Set largest to $N_{j}$ $\bullet\quad\quad\quad$ Set location to $j$ $\bullet \quad\quad$ Increment $j$ by 1 $\bullet\quad$ End of loop $\bullet\quad$ Set the value of $N_{i}$ to the value of $N_{j}$ $\bullet\quad$ Set the value of $N_{j}$ to the value of Store $\bullet\quad$ Decrease $i$ by 1 $\bullet$ End of loop $\bullet$ Print the sorted list: $N_{1}, N_{2}, \ldots N_{n}$

Work Step by Step

--
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.