Find the intersection of two given LinkedList (where each node has a character). Return the LinkedList which has character which appears in both LinkedList (same sequence order as LinkedList1).
error:variable temp might not have been initialized
I tried a lot to resolve this error, but I cant step forward in this problem. Please help to resolve my error.
public SchNode func(SchNode head1, SchNode head2)
{
SchNode temp;
for(SchNode ptr=head1;ptr!=null;ptr=ptr.nextNode)
{
for(SchNode ptr2=head2;ptr2!=null;ptr2=ptr2.nextNode)
{
if(ptr.ch==ptr2.ch)
{
temp.ch=ptr2.ch;
temp=temp.nextNode;
}
}
}
return temp ;
}
You can use this method if don't understand it wrong.
list1length, lets call itAlist2length, lets call itBC = A - BchoosenListchoosenList[abs(C)] //i mean absolute value of CEDIT: what i understand is you have two linked lists that have a common node(pointer)