1.

Consider the following unsorted list:99 78 25 48 51 11Sort the list using selection sort algorithm. Show the status of the list after every iteration.

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

DATA_LIST = [99 78 25 48 51 11]

print “LIST BEFOR SORTING”,DATA_LIST

selection_sort(DATA_LIST)



Discussion

No Comment Found

Related InterviewSolutions