Quick actions

cmd+k|ctrl+k

Navigation

Languages

Selection sort by Moin

Snippet info

Language

Python

Visibility

public

Author

moin778866.ma

Created

2022-07-21T19:07:51.318389Z

Updated

2022-07-21T19:07:51.318389Z

# sorting algorithm --> Selection sort
# selection sort works by taking the minium element out of the given array and putting it on first
# then leaving that element we look for another minimum element and put it on second and hence forth process continues

arr =[4,6,8,2,7,0,5] # 7


array_length = len(arr)
for j in range(array_length):
    min = arr[j]
    for i in range(j,array_length):
        if min > arr[i]:
            min = arr[i]
            index = i   
    arr[j], arr[index] = min, arr[j]
    print(arr)
        

INFO