Mitko

12-03-2011, 12:38 AM

Hey I am a first year unversity student and my project was to do a selection sort using recursion. I have figured out how to do it, but i don't know how to do it with recursion any help please?

def selsort(l):

"""

sorts l in-place.

PRE: l is a list.

POST: l is a sorted list with the same elements; no return value.

"""

for pos in range(len(l)-1):

largest = l[pos]

largestpos = pos

for i in range(pos+1, len(l)):

if l[i] > largest:

largest = l[i]

largestpos = i

l[pos], l[largestpos] = l[largestpos], l[pos]

l.reverse()

def selsort(l):

"""

sorts l in-place.

PRE: l is a list.

POST: l is a sorted list with the same elements; no return value.

"""

for pos in range(len(l)-1):

largest = l[pos]

largestpos = pos

for i in range(pos+1, len(l)):

if l[i] > largest:

largest = l[i]

largestpos = i

l[pos], l[largestpos] = l[largestpos], l[pos]

l.reverse()