Quick actions

cmd+k|ctrl+k

Navigation

Languages

Selection Sort 🔥

Snippet info

Language

Python

Visibility

public

Author

krishnakanth

Created

2023-08-21T15:16:45.148856Z

Updated

2023-08-21T15:18:54.482032Z

arr = list(map(int,input().split()))


def SelectionSort(arr,n):
    
    for i in range(n):
        temp = i+1
        m = i
        while temp < n:
            if arr[m] > arr[temp]:
                m = temp
            temp += 1
        
        arr[i],arr[m] = arr[m],arr[i]
        
    return arr




print(SelectionSort(arr,len(arr)))

#########################################################

# def SelectionSort(l):

# # Scan slices l[0:len(l)], l[1:len(l)], ...
# for start in range(len(l)):

# # Find minimum value in slice . . .
# minpos = start
# for i in range(start,len(l)):

# if l[i] < l[minpos]:
# minpos = i

# # . . . and move it to start of slice
# (l[start],l[minpos]) = (l[minpos],l[start])
INFO