Function to check if two input lists have same data
function compareLists ( head1 , head2 ) { var temp1 = head1 ; var temp2 = head2 ; while ( temp1 != null && temp2 != null ) { if ( temp1 . data == temp2 . data ) { temp1 = temp1 . next ; temp2 = temp2 . next ; } else return false ; }