Bubble Sort
About
The simplest sorting algorithm, it's a Greedy algorithm. Basically starts at first DS position and checks if it is greater than the next one, and keeps repeating this process until it is done.
Implementation on Arrays
function bubbleSort(arr: number[]): void {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < (arr.length - 1 - i); j++ ) {
if (arr[j] > arr[j + 1]) {
const tmp = arr[j];
arr[j] = arr[j + 1];
arr[j+1] = tmp;
}
}
}
}Last updated