• Post Reply Bookmark Topic Watch Topic
  • New Topic

selection sort: did i miss something?!  RSS feed

 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never did sort(s) before; thought i'd try it out ... so could somebody tell me how i screwed this up__



it makes sense to me, but my output:



gawd i hope this ain't so simple that i crawl into a hole... thanks in advance

n
>
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You are swapping the inner and outer value un-conditionally. So you are effectively shuffling the numbers but are not sorting them. I assume you want to only swap the values if the condition is met. I am also not convinced you are comparing the correct values (inner with minimum then resetting minimum). I think you can drop the use of minimum all together...
 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:

You are swapping the inner and outer value un-conditionally. So you are effectively shuffling the numbers but are not sorting them. I assume you want to only swap the values if the condition is met. I am also not convinced you are comparing the correct values (inner with minimum then resetting minimum). I think you can drop the use of minimum all together...


Umm, okay the "><" was a copy paste botch, this is illegal in java, try it. it should only be : "<" since compareTo() returns less than 0 if the Strings are not equal. this code is adapted from Robert LaFore. so if you have another algorithm that works with Strings i'd be more than glad to use it ... i already had to edit the previous post so hopefully this will go through okay.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this,


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!