Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 1.32 KB

README.md

File metadata and controls

16 lines (14 loc) · 1.32 KB

BubbleSort

Bubble Sort Algorithm for Swift Coding Club Advance

What is Bubble Sort??

Bubble_sort_animation bubble-short

  • Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the input list element by element, comparing the current element with the one after it, swapping their values if needed. These passes through the list are repeated until no swaps had to be performed during a pass, meaning that the list has become fully sorted. The algorithm, which is a comparison sort, is named for the way the larger elements "bubble" up to the top of the list.

How it work??

  1. Start at the beginning of the list.
  2. Compare the first item to the second item. If the first item is greater than the second item, swap them.
  3. Move on to the next pair of items and repeat the comparison. If the second item is greater than the third item, swap them.
  4. Continue this process until you reach the end of the list.
  5. If you made any swaps, go back to the beginning of the list and repeat the process until you can go through the entire list without making any swaps.