0
def selsort(l):
 

    if len(l)<=1:
        return l
    else:
        for i in range(len(l)):
            selsort(l[1:])

Hey guys, this is what I have so far. I have trouble understanding recursion. Anyone know how to use it to do selection sort?

2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by Dhaneshnm
1

you just have to modify else part a little
1.assign the result of recursive call to your list(l)
2.u r using the for loop to find smallest number in the list right?so put the above assignment out of the loop.
3.swap the smallest element with the first element of the list.


happy coding

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.