Invitation to Computer Science 8th Edition

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

Chapter 3 - Exercises - Page 142: 14a


Notice the extra pieces that makes it different from the simple bubble sort. $\bullet$ Get values of $n$ and the list elements $\bullet$ Set marker $U$ for the unsorted section at the end of the list $\bullet$ Set value of sorted to $N O$ $\bullet$ While the unsorted part has more than one element AND sorted = NO do $\bullet\quad$ Set current element marker $C$ at second element of the list $\bullet\quad$ Set value for count to 0 $\bullet\quad$ While $C$ has not passed $U$ do $\bullet \quad\quad$ If item at position $C$ is less than the item on the left then $\bullet \quad\quad\quad$ Exchange these two items $\bullet\quad\quad\quad$ Add 1 to the value of count $\bullet\quad\quad$ Move $C$ one position to the right $\bullet\quad$ Move $U$ one position to the left $\bullet\quad$ If count $>0$ then set sorted to $Y E S$ $\bullet$ Stop.

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.