Lunes, Pebrero 20, 2012

bubble sort

From Wikipedia
Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements “bubble” to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort.
[ad code=1]
[ad code=1]

Algorithm

  1. Iterates thru every element of the array, starting with the first 2 elements.
  2. If left element is bigger than right element, swap them.
  3. Repeat step #1 and #2 until there are no more swaps.
[ad code=1]
[ad code=1]

Block Diagram

Walang komento:

Mag-post ng isang Komento