def bubble_sort(collection):
          length = len(collection)
          for i in range(length - 1):
              swapped = False
              for j in range(length - 1 - i):
                  if collection[j] > collection[j + 1]:
                      swapped = True
                      collection[j], collection[j + 1] = collection[j + 1], collection[j]
              if not swapped:
                  break 
          return collection
      
      Python language logo

      Bubble Sort

      Python
      BubbleSort
      HGV Public Cookbook

      Function to perform Bubble sort

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.