Bubble sort is one of the slowest, but also simplest sorting algorithms out there.
line 1: we loop through the array.length - 1, because we won't be comparing the last element. line 2: we loop through the array.length - 1 - j, because we need (n-2) iterations at the 2nd pass and (n-3) at the third pass.. and so on line 3: if current member is bigger than element to the right, we swap them |