Bubble Sort

    0

    0

    HARIGOVIND VALSAKUMAR

    PythonBubbleSort
    HGV Public Cookbook

    Function to perform Bubble sort

    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
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.