Selection Sort

    0

    0

    Aakanksha Priya

    def selection_sort(unsorted_arr):
        for idx in range(len(unsorted_arr)):
            min_idx = idx
            for j in range( idx +1, len(unsorted_arr)):
                if unsorted_arr[min_idx] > unsorted_arr[j]:
                    min_idx = j
    # Swap the minimum value with the compared value
            unsorted_arr[idx], unsorted_arr[min_idx] = unsorted_arr[min_idx], unsorted_arr[idx]
    arr= [45,89,56,78,90,12,10,2,34,1]
    selection_sort(arr)
    print(arr)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.