Selection Sort using recursion

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 12
Reputation: docaholic is an unknown quantity at this point 
Solved Threads: 1
docaholic docaholic is offline Offline
Newbie Poster

Selection Sort using recursion

 
0
  #1
Mar 22nd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 51
Reputation: Dhaneshnm is an unknown quantity at this point 
Solved Threads: 6
Dhaneshnm's Avatar
Dhaneshnm Dhaneshnm is offline Offline
Junior Poster in Training

Re: Selection Sort using recursion

 
1
  #2
Mar 23rd, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 1117 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC