Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2009
    Posts
    31
    Rep Power
    0

    Default Need help with sorting a linked list

    I have a linked list class that will have two trails of references. One that follows the trail of references as they were added to the list and the other follows the trail of references in numeric order. My add method is below. This method sets the links to the addedOrder list which is just the variable link, and the second if statement in the while loop is supposed to sort these and set the sortLink variables. This method isn't setting the sortLink variables right. What am I doing wrong? Your help is very much appreciated.
    Java Code:
    public void addDualNode(String newData){
            DualNode position = head;
            while(position!=null){
                if(position.getLink()==null){
                position.setLink(new DualNode(newData));
                break;
                }
             if(Integer.parseInt(position.getLink().getData())>Integer.parseInt(position.getData())){
                position.setSortLink(position.getLink());
                }
                position = position.getLink();
            }//end while
    
        }//end method
    Last edited by SteroidalPsycho; 05-04-2010 at 01:23 AM.

Similar Threads

  1. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  2. Linked List
    By basma in forum JCreator
    Replies: 0
    Last Post: 02-03-2010, 08:34 AM
  3. Sorting a linked list
    By Hayzam in forum New To Java
    Replies: 4
    Last Post: 01-18-2009, 12:07 AM
  4. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  5. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 03:42 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
  •