Shell Sort

    0

    0

    Aakanksha Priya

    def shellSort(unsorted_arr):
        gap = len(unsorted_arr) // 2
        while gap > 0:
            for i in range(gap, len(unsorted_arr)):
                temp = unsorted_arr[i]
                j = i
    # Sort the sub list for this gap
        while j >= gap and unsorted_arr[j - gap] > temp:
            unsorted_arr[j] = unsorted_arr[j - gap]
            j = j-gap
            unsorted_arr[j] = temp
    # Redu ce the gap for the next element
        gap = gap//2
    arr= [45,89,56,78,90,12,10,2,34,1]
    shellSort(arr)
    print(arr)
    
    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.