tungggg

compareLinkedlistRecursion

Apr 22nd, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
  2.     if (head1->data != head2->data )  return 0 ;
  3.     if ( head1->next == nullptr  && head2->next == nullptr ) return 1;
  4.     if ( head1->next == nullptr  && head2->next != NULL ) return 0 ;
  5.     if (head2->next == NULL && head1->next != NULL) return 0;
  6.     return compare_lists(head1->next,  head2->next);
  7.  
  8. }
  9.  
Advertisement
Add Comment
Please, Sign In to add comment