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

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




ordered list link

 
Reply to this topicStart new topic

ordered list link, why is this approach not working

debeth
6 Aug, 2008 - 09:28 AM
Post #1

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

Well i redid this and it still says error no such method ???
Why is it not merging my two list???
CODE
public void mergeLists(OrderedLinkedList<T> list1, OrderedLinkedList<T> list2)
  {
      int lastlist,newList;
      
      if(list1 == null)
          return list2; //the firstsublist is empty
      else
          if (list2 == null)
              return list1;
          else
          {Comparable<T> compElem = (Comparable<T>)list1.info;
          
          if( compElem.compareTo(list2.info) < 0)//compares the first node
          {
              newList = list1;
              list1 = list1.link;
              lastlist= newList;
          }    
              else
              {
                  newList= list2;
                  list2=list2.link;
                  lastlist = newList;
              }
          }
          while (list1 !=null&& list2 !=null)    
          {
              Comparable<T> compElem= (Comparable<T>)list1.info;
              
              if(compElement.compareTo(list2.info) <0)
              {
                  lastlist.link = list1;
                  lastlist =lastlist.link;
                  list1 = list1.link;
              }
              else
              {
                  lastlist.link=list2;
                  lastlist = lastlist.link;
                  list2 = list2.link;
              }
          }    //end while
          if(list1 == null)
              lastlist.link = list2;
           else
               lastlist.link = list1;
           return newList;        
      }
}
  

any direction...Please d

User is offlineProfile CardPM
+Quote Post

lordms12
RE: Ordered List Link
6 Aug, 2008 - 11:08 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
Not enough code, I think
User is offlineProfile CardPM
+Quote Post

debeth
RE: Ordered List Link
6 Aug, 2008 - 11:25 AM
Post #3

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

QUOTE(lordms12 @ 6 Aug, 2008 - 12:08 PM) *

Not enough code, I think


do you need the whole project???
i revised a little the errors gone but its not working..
<
CODE
>public void mergeLists(OrderedLinkedList<T> list1, OrderedLinkedList<T> list2)
  
  { LinkedListNode<T> lastMerged;//variable to last node
    LinkedListNode<T> newList;// merge list
      
      if(list1 == null)
          return list2; //the firstsublist is empty
      else
          if (list2 == null)
              return list1;
          else
          {Comparable<T> compElement = (Comparable<T>)list1.info;
          
          if( compElement.compareTo(list2.info) < 0)//compares the first node
          {
              newList = list1;
              list1 = list1.link;
              lastMerged= newList;
          }    
              else
              {
                  newList= list2;
                  list2=list2.link;
                  lastMerged = newList;
              }
          //}
          while (list1 !=null&& list2 !=null)    
          {
              Comparable<T> compElement= (Comparable<T>)list1.info;
              
              if(compElement.compareTo(list2.info) <0)
              {
                  lastMerged.link = list1;
                  lastMerged=lastMerged.link;
                  list1 = list1.link;
              }
              else
              {
                  lastMerged.link=list2;
                  lastMerged = lastMerged.link;
                  list2 = list2.link;
              }
          }    //end while
          if(list1 == null)
          {    lastMerged.link = list2;
          }
           else
           {    lastMerged.link = list1;}
           return newList;        
                                  
          }
  }
  
      <

this is the revised what else do you need?....d

User is offlineProfile CardPM
+Quote Post

debeth
RE: Ordered List Link
6 Aug, 2008 - 12:15 PM
Post #4

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

okay i was told not to use returns but to set the pointers.
well i need 3 pointers right.??..............d
User is offlineProfile CardPM
+Quote Post

debeth
RE: Ordered List Link
6 Aug, 2008 - 12:29 PM
Post #5

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

QUOTE(debeth @ 6 Aug, 2008 - 01:15 PM) *

okay i was told not to use returns but to set the pointers.
well i need 3 pointers right.??..............d

java
 public void mergeLists(OrderedLinkedList<T> list1, OrderedLinkedList<T> list2)

{ LinkedListNode<T> lastMerged;//variable to last node
LinkedListNode<T> secnod;// variable to firstnode in list2
LinkedListNode<T> frstnod;//variable to firstnodein list1

if(list1.first == null)
lastMerged=list2.first;
else
if (list2.first == null)
lastMerge=list1.first;
else
{Comparable<T> compElement = (Comparable<T>)list1.info;

if( compElement.compareTo(list2.info) < 0)//compares the first node
{
newList = list1;//What goes here
list1 = list1.link;//What goes here
lastMerged= newList;//What goes here
}
else
{
newList= list2;
list2=list2.link;
lastMerged = newList;
}
//}
while (list1 !=null&& list2 !=null)
{
Comparable<T> compElement= (Comparable<T>)list1.info;

if(compElement.compareTo(list2.info) <0)
{
lastMerged.link = list1;
lastMerged=lastMerged.link;
list1 = list1.link;
}
else
{
lastMerged.link=list2;
lastMerged = lastMerged.link;
list2 = list2.link;
}
} //end while
if(list1 == null)
{ lastMerged.link = list2;
}
else
{ lastMerged.link = list1;}
return newList;

}
}


how do i set these pointers??

User is offlineProfile CardPM
+Quote Post

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

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