Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2.
Hi,
This is very simple. Did you tried anything? Please post here what you tried then ask questions on that.
Thanks,
i tried this
public static list ( list L1 , list L2 ){
list L = new list ();
listNode temp1=L1.first;
listNode temp2 = L2.first ;
listNode temp3 = L.first ;
while ( temp1 !=null){
temp3= temp1.data + temp2>data;
temp3.next=newNode();
temp1=temp1.next;
temp2 = temp.next;
temp 2 = temp3>next ;
}
return L;
}
but it dosent work in netbean
" i didnt anitial temp or data becouse i didnt know how and where in this program "
if any one can help me to write it all with its class , i will be greatfull for him .
Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.
Please post code correctly. Define "dosent (sic) work." If you're getting errors, post those. If you're getting incorrect results, post those.
still i cant do it
Please explain. Copy the program's output and paste it here to show what the program is doing.i cant do it
Please edit your post and wrap your code with code tags:
[code=java]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.