| | |
What's the most efficent way to randomize a Queue?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
I've seen a lot of different possible ways to do so, but I was wondering what people thought the most efficient way was.
My Website <-- check out my site!
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
Ok, so say you have a queue with values in it, then you want to randomize the order that they are currently in.
My Website <-- check out my site!
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
I think you still don't get it....Say there is a queue with elements a, b and c in that order. I want to know what the best way to put the elements in a random order, so you might save the elements off to an array shuffle them, and then put them back into the queue so the new order in the queue would be b, a, c.
But keep in mind a, b, and c are just arbitrary elements if that helps you understand it....
But keep in mind a, b, and c are just arbitrary elements if that helps you understand it....
My Website <-- check out my site!
The simplest way would be to use the Collections#shuffle(List<?> list) method which delivers decent performance and output.
If you have an assignment to create such a shuffling algorithm, then look at the source code of the Collections class for hints.
If you have an assignment to create such a shuffling algorithm, then look at the source code of the Collections class for hints.
I don't accept change; I don't deserve to live.
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
Yeah collections sounds like a good way to go since the shuffle method is built right in, thanks.
My Website <-- check out my site!
![]() |
Other Threads in the Java Forum
- Previous Thread: Returning string from method help
- Next Thread: please help in Jdbc connectivity
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






