First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

write a program for selection sort in c & python

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
more_vert
def selection_sort(list):
    for i in range(0, len(list) - 1):
        smallest = i
        for j in range(i + 1, len(list)):
            if list[j] < list[smallest]:
                smallest = j
        list[i], list[smallest] = list[smallest], list[i]
list = input('enter the list').split()
list = [int(x) for x in list]
selection_sort(list)
print('Sorted list: ',list)
more_vert

Thanks for program

1 Answer

more_vert
 
verified
Best answer

Python Program

 def selection_sort(list):
    for i in range(0, len(list) - 1):
        smallest = i
        for j in range(i + 1, len(list)):
            if list[j] < list[smallest]:
                smallest = j
        list[i], list[smallest] = list[smallest], list[i]
list = input('enter the list').split()
list = [int(x) for x in list]
selection_sort(list)
print('Sorted list: ',list)
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
...