Results 1 to 2 of 2
Thread: Combining linked lists.
- 04-25-2012, 01:28 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
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; } } } }
- 04-25-2012, 01:52 AM #2
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
-
concatenating linked lists
By coder94 in forum New To JavaReplies: 1Last Post: 02-28-2011, 06:16 AM -
Linked Lists
By Dee in forum New To JavaReplies: 18Last Post: 02-02-2011, 03:14 AM -
Linked Lists
By vendetta in forum New To JavaReplies: 6Last Post: 01-26-2010, 08:23 AM -
Single linked lists - help
By Srcee in forum New To JavaReplies: 10Last Post: 10-29-2009, 05:35 PM -
Doubly Linked Lists
By stevenson15 in forum New To JavaReplies: 6Last Post: 04-21-2009, 12:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks