Results 1 to 5 of 5
  1. #1
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default Sorting a linked list

    well i have a linked list of node " process "

    Java Code:
    public class process 
    {
        int arrival_time,burst_time,turn_around_time,waiting_time,response_time;
        char name;
    
    }
    and i would like to sort it in ascending order according to the values in the arrival_time ..

    how can i do that ?!

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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

  3. #3
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default

    i am not understanding .
    the process is the node of my linked list ....

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    What if you made process implement the Comparable<process> interface and then sorted the list via Collections.sort(myProcessList)?

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    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.

Similar Threads

  1. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM
  2. Linked List Question
    By CirKuT in forum New To Java
    Replies: 4
    Last Post: 12-10-2008, 07:56 PM
  3. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 04:15 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 04:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •