Difference between revisions of "W1352 Bubble Sort"
From Coder Merlin
(Created page with "DRAFT ICON == Exercises == # Complete Merlin exercise 1851") |
|||
Line 1: | Line 1: | ||
[[File:DRAFT ICON.png|DRAFT ICON]] | [[File:DRAFT ICON.png|DRAFT ICON]] | ||
== Research == | |||
* Read [https://en.wikipedia.org/wiki/Bubble_sort Bubble Sort (Wikipedia)] | |||
* View [https://www.youtube.com/watch?v=nmhjrI-aW5o Bubble Sort (Geeks for Geeks)] | |||
== Exercises == | == Exercises == | ||
# Practice with Playing Cards | |||
## Shuffle a “deck” of 13 cards. | |||
## Lay out every card in the deck, horizontally, face-up, from left-to-right. | |||
## Record the ordering of the deck on a tracking sheet. | |||
## Place a two-headed pointer on the left-hand side so that it’s pointing at the first and second card. | |||
## If the first card is greater in value than the second card, swap the two cards. If a swap occurs, make a tick mark on the tracking sheet. | |||
## Whether a swap occurred or not, advance the pointer forward (to the right) by one card, so that it’s now pointing at the second and third cards. | |||
## Again make a comparison following the above rules for swapping. | |||
## Continue to track any swaps that occur and advance the pointer until reaching the right-end side of the deck. | |||
## At this point, the first pass has completed. Record the number of swaps that occurred during this pass. | |||
## If any swaps occurred during the pass, begin a new pass by repeating this procedure, moving the pointer back to the beginning on the far, left-hand side and moving to the right again. | |||
## When no swaps have occurred during a pass, you’re done. | |||
# Complete Merlin exercise 1851 | # Complete Merlin exercise 1851 |
Revision as of 17:47, 7 April 2019
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Research[edit]
Exercises[edit]
- Practice with Playing Cards
- Shuffle a “deck” of 13 cards.
- Lay out every card in the deck, horizontally, face-up, from left-to-right.
- Record the ordering of the deck on a tracking sheet.
- Place a two-headed pointer on the left-hand side so that it’s pointing at the first and second card.
- If the first card is greater in value than the second card, swap the two cards. If a swap occurs, make a tick mark on the tracking sheet.
- Whether a swap occurred or not, advance the pointer forward (to the right) by one card, so that it’s now pointing at the second and third cards.
- Again make a comparison following the above rules for swapping.
- Continue to track any swaps that occur and advance the pointer until reaching the right-end side of the deck.
- At this point, the first pass has completed. Record the number of swaps that occurred during this pass.
- If any swaps occurred during the pass, begin a new pass by repeating this procedure, moving the pointer back to the beginning on the far, left-hand side and moving to the right again.
- When no swaps have occurred during a pass, you’re done.
- Complete Merlin exercise 1851