March 2019
Intermediate to advanced
336 pages
9h 9m
English
The bubble sort algorithm is a sorting algorithm that compares a pair of neighboring elements and swaps them if they are in the wrong order. The algorithm has a complexity of O(n2), where n is the number of elements to be sorted. The smallest or greatest value bubbles up to the top of the collection, or the smallest or greatest sinks to the bottom (depending on whether you're sorting into ascending or descending order).
The following code snippet shows the implementation of the bubble sort algorithm. The bubbleSorter function takes an integer array and sorts the array's elements in ascending order.
The main method initializes the array's integers and invokes the bubbleSorter function, as follows:
//main package has examples shown ...
Read now
Unlock full access