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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.