Results 1 to 2 of 2
  1. #1
    syle_q is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Default Combining linked lists.

    I wrote a method that combines two linked lists that are populated with "textbook" objects. Both of the list are sorted alphabetically sorted prior to joining and the final list after joining should also be alphabetically sorted. I wrote a method with what I thought might work but nothing happens, can anyone tell me why nothing is done from this code.

    ***neither of the lists are empty***

    Java Code:
        public void join(DLinkedList other) {
    
            Node tempOne = head;
            Node tempTwo = other.head;
            
            if(this.isEmpty()== true || other.isEmpty() == true){
                System.out.println("Need two populated lists to perform join operation");
                return;
            }
            
            while( tempOne != null && tempTwo != null){
                
                if(tempTwo.compareTo(head) < 0){
                    Node insert = tempTwo;
                    insertHead(insert);
                    tempTwo = tempTwo.fpointer;
                }
                
                if(tail.compareTo(tempTwo) < 0){
                    Node insert = tempTwo;
                    insertTail(insert);
                    tempTwo = tempTwo.fpointer;
                }
                
                
                if(tempOne.compareTo(tempTwo) < 0){
                    tempOne = tempOne.fpointer;
                    
                    if(tempOne.compareTo(tempTwo) > 0){
                        Node insert = tempTwo;
                        insert.fpointer = tempOne;
                        insert.bpointer = tempOne.bpointer;
                        tempOne.bpointer.fpointer = insert;
                        tempOne.bpointer = insert;
                        tempTwo = tempTwo.fpointer;
                        
                    }
                }
            }
           
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default Re: Combining linked lists.

    Can you make a small, complete program that compiles, executes and shows the problem?

    Try debugging your code by adding lots of println statements that show where the execution flow goes and what the values of the variables are as the code executes and as the variables values are changed and used.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. concatenating linked lists
    By coder94 in forum New To Java
    Replies: 1
    Last Post: 02-28-2011, 06:16 AM
  2. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 03:14 AM
  3. Linked Lists
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-26-2010, 08:23 AM
  4. Single linked lists - help
    By Srcee in forum New To Java
    Replies: 10
    Last Post: 10-29-2009, 05:35 PM
  5. Doubly Linked Lists
    By stevenson15 in forum New To Java
    Replies: 6
    Last Post: 04-21-2009, 12:35 PM

Posting Permissions

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