[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/shreydan/Python/master/code/Algorithms/Sorting/selection.py [Back]  [Original]

# selection sort

def selection(sortlist):
	""" checks for the largest and then replaces - ascending order only"""
	
	for i in range(0,len(sortlist)-1):
		small = sortlist[i]
		pos = i
		for j in range(i+1,len(sortlist)):
			if sortlist[j] < small:
				small = sortlist[j]
				pos = j
		
		sortlist[pos] = sortlist[i]
		sortlist[i] = small;
		
	return sortlist
		

Web Proxy Viewer  |  New URL  |  Original Page