def bsortOne(l: list): for i in range(len(l) - 1): if (l[i] >= l[i + 1]): temp = l[i] l[i] = l[i + 1] l[i + 1] = temp return l def bsortAll(l: list): i = 0 while i < (len(l) - 1): bsortOne(l) i = i + 1 return l l = [9, 88, 2, 1, 4, 1] print(bsortAll(l))
class Solution: def sortone(self, l: list, n: int) -> list: for i in range(0, n - 1): if l[i] > l[i + 1]: temp = l[i + 1] l[i + 1] = l[i] l[i] = temp return l def sortAll(self, l): for i in range(len(l), 1, -1): self.sortone(l, i) return l l = [6, 5, 4, 3, 2] print(Solution().sortAll(l))