Description: |
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. You can see the code implementation below:
|
Code: | ||
|
Output: |
2, 4, 6, 9, 12, 23, 0, 1, 34, 2, 4, 6, 9, 12, 0, 1, 23, 34, 2, 4, 6, 9, 0, 1, 12, 23, 34, 2, 4, 6, 0, 1, 9, 12, 23, 34, 2, 4, 0, 1, 6, 9, 12, 23, 34, 2, 0, 1, 4, 6, 9, 12, 23, 34, 0, 1, 2, 4, 6, 9, 12, 23, 34, 0, 1, 2, 4, 6, 9, 12, 23, 34, 0, 1, 2, 4, 6, 9, 12, 23, 34, 0, 1, 2, 4, 6, 9, 12, 23, 34, |
No comments:
Post a Comment