Results 1 to 5 of 5
Thread: Sorting a linked list
- 01-17-2009, 11:43 PM #1
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
Sorting a linked list
well i have a linked list of node " process "
and i would like to sort it in ascending order according to the values in the arrival_time ..Java Code:public class process { int arrival_time,burst_time,turn_around_time,waiting_time,response_time; char name; }
how can i do that ?!
- 01-17-2009, 11:52 PM #2
Java Code:public class process { TreeMap<Integer,prcocess> tm = new TreeMap<Integer,prcocess>(); void public load (prcocess p){ tm.put(new Integer(p.arrival_time),new process(process)); } }Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 01-17-2009, 11:56 PM #3
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
i am not understanding .
the process is the node of my linked list ....
-
What if you made process implement the Comparable<process> interface and then sorted the list via Collections.sort(myProcessList)?
- 01-18-2009, 12:07 AM #5
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
If you really want to sort a linked list, just pass a corresponding LinkedList object into Collections.sort() like any other list.
I think Nicholas' point is that a linked list isn't really a good candidate for sorting; you should consider another more appropriate structure.Neil Coffey
Javamex - Java tutorials and performance info
Similar Threads
-
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM -
Linked List Question
By CirKuT in forum New To JavaReplies: 4Last Post: 12-10-2008, 06:56 PM -
Linked List help
By neobie in forum New To JavaReplies: 8Last Post: 12-22-2007, 03:15 AM -
Linked List
By rnavarro9 in forum New To JavaReplies: 0Last Post: 11-29-2007, 03:42 AM -
Help with linked list
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks