Repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. Return the sorted array.