selection sort (using auxilary list)

import sys #for using maximum integer value (maxint) def selection_sort(lst): result=[] while True : i=1 j=0 min_num=lst[0] while i<len(lst): if lst[i]<min_num : min_num=lst[i] j=i i+=1 result.append(min_num) lst[j]=sys.maxint k=0 temp=0 while k<len(lst): if lst[k]!=sys.maxint : temp=1 k+=1 if temp==0 : break return result my_nums=[] import random for i in range (1000): my_nums.append(random.randint(1,1000)) print selection_sort(my_nums)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.