Sunday, February 23, 2014

Bubble Sort in Java

Refer: Main indexed article on sorting.


Bubble sort is a simple sorting algorithm that works by:
  • Repeatedly going through the list to be sorted
  • Comparing each pair of adjacent items
  • Swapping them if they are in the wrong order
The above steps are repeated till no swaps are needed.
This indicates that the list is sorted.

Note: Bubble sort should be avoided in case of large collections (large number of elements).

Algorithm:



Java code Snippet:

No comments:

Post a Comment