I am planning to write a Java Function that takes two linked lists. Both have the same size. I want to return a new list that contains the maximum of the data found in the corresponding nodes of the two lists passed to my function.
However I am stuck in filling the new list. I came up with this:
function max2List (LinkedList list1 , LinkedList list2) {
LinkedList <int> list3 = new LinkedList<int> ();
for (ListNode p = list1.first ; p!=null; p=p.next) {
for (ListNode p = list2.first ; p!=null; p=p.next) {
if (list1.p.data > list2.p.data ) {
//return list3 here with big value
else if (list1.p.data < list2.p.data ) {
//return list3 here with big value
I don't know how to continue. I want list3 to contain the maximum values from the two lists.