Welcome to Dream.In.Code
Become a Java Expert!

Join 150,138 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,277 people online right now. Registration is fast and FREE... Join Now!




ordered link list merge

 
Reply to this topicStart new topic

ordered link list merge, Am i on the right track??

debeth
5 Aug, 2008 - 09:35 AM
Post #1

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

MY assignment is to merge two link list.
I have the search,insert,first and last, deleteNod methods also the main method
but this code is throwwing a Nosuch method error.

CODE
public void mergeLists(OrderedLinkedList<T> list1, OrderedLinkedList<T> list2)
   {
        int newList= result;
    while length( list1) > 0 and length(list2) > 0
        if first(list1) ≤ first(list2)
            append first( list1) to result
            list1 = rest(list1)
        else
            append first(list2) to result
            list2 = rest(list2)
    end while
    if length(list1) > 0
        append rest(list1) to result
    if length(list2) > 0
        append rest(list2) to result
    return result

   }
  


Do i have to have a sort method before a merge or can i just merge?
Am i on the right track?...........D
User is offlineProfile CardPM
+Quote Post

pbl
RE: Ordered Link List Merge
5 Aug, 2008 - 03:50 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
I don't know what your OrderedLinkedList class looks like but its name suggests that it is a class whose objects hold a LinkedList of objects according to a certain order.

This class must have a add(Object) method that scans the list to find out between which 2 nodes it should insert the Object passed as parameter.

So just scan the first list and insert all of its objects into the second one.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:09AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month