merging 2 linked list into 1
|
|||
|
Rank: ? (11)
Member #: 28462 |
Write a Java program that contains a method with the capability to merge two linked lists (list1 and list2 in the figure) containing objects (can be integer, double, string) that are in ascending order. The merged result should be in the third linked list (list3) that is in sorted order. Do not destroy the original lists. Your program should output the content of three linked lists to show the program performs properly. Create as many methods as you see fit.
can you guys give me ideas? i know it also has to read the data thats in the list's from an input file. i will post code when i get it all written |
||
|
|||
|
|||
|
Rank: ? (119)
Member #: 28292 |
The simplest way to do it is creating of the list3 that is so long as length of list1 and list2. Than copy the content of the list1 and list2 to the list3. Than you can sort the list3.
|
||
|
|||
|
|||
|
Rank: ? (4821)
Member #: 3416 |
i would approach it by creating list3 as an empty linked list, then adding items from list1 and then list2 one item at a time, making sure to insert into list3 in the correct position so that it ends up sorted.
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (11)
Member #: 28462 |
is comparing 2 linked list the same as comaring 2 arrays? use a for loop?
|
||
|
Please login or register to post a reply.