+2 votes
in Class 12 by kratos

Consider the following unsorted list Neena Meeta Geeta Reeta Seeta Sort the list using selection sort algorithm. Show the status of the list after every iteration.

1 Answer

+4 votes
by kratos
 
Best answer

def selection_sort(DATA_LIST):

for i in range(0, len (DATA_LIST)):

min = i

for j in range(i + 1, len(DATA_LIST)):

if DATA_LIST[j] < DATA_LIST[min]:

min = j

swapping

temp= DATA_LIST[min]

DATA_LIST[min] = DATA_LIST[i]

DATA_LIST[i]=temp

print DATA_LIST

NAME_LIST = [‘Neena’,’Beeta’,’Reeta’,’Geeta’,’Seeta’]

print “LIST BEFORE SORTING”,NAME_LIST

selection_sort(NAME_LIST)

LIST BEFORE SORTING [‘Neena’,‘Beeta’,‘Reeta’, ‘Geeta’, ‘Seeta’]

[‘Beeta’, ‘Neena’, ‘Reeta’, ‘Geeta’, ‘Seeta’]-Pass 1

[‘Beeta’, ‘Geeta’, ‘Reeta’, ‘Neena’, ‘Seeta’]-Pass 2

[‘Beeta’, ‘Geeta’, ‘Neena’, ‘Reeta’, ‘Seeta’]-Pass 3

[‘Beeta’, ‘Geeta’, ‘Neena’, ‘Reeta’, ‘Seeta’]-Pass 4

[‘Beeta’, ‘Geeta’, ‘Neena’, ‘Reeta’, ‘Seeta’]-Pass 5

...