Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

selection sort on linklist

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any other way to do the selection sort?
I am trying to use selection sort on a linklist to sort Double numbers. I wrote a method to find the smallest number as follows:

Then I used the thePosition which is a LinkList to swap the first value with the smallest. For that I wrote another method as follows:

I thought since in for loop it says p = p.itsNext, it will find the smallest value in the emaining list afte it swapped the smallest value with the 1st value in the list. Somehow its is not sorting properly. What am i doing wrong? Or is there any other way to do the selection sort? Removing the largest number & putting it, doesn't work as it inserts the number after the 1st value - a friend has already tried that. Please help!!!
(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited May 14, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you left out some stuff.
itsNext //this is not a method, so is it a field?
itsData //ditto
isEmpty() //where is this
thePosition // not defined locally???

Why would you set p=r and then in the for loop reset it to "this" instead of what was explicitely passed in?
Is this compiling at all???
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is posted in Intermediate, so I am closing it here.
 
I like tacos! And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!