You are viewing a single comment's thread. Return to all comments →
This is my code. JAVA
static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { Boolean check = Boolean.TRUE; SinglyLinkedListNode head1Root = head1; SinglyLinkedListNode head2Root = head2; sizeOfList(head1); sizeOfList(head2); head1 = head1Root; head2 = head2Root; if (sizeOfList(head1) == sizeOfList(head2)) { while (head1.next != null) { if (head1.data == head2.data) { head1 = head1.next; head2 = head2.next; } else { check = Boolean.FALSE; break; } } } else { check = Boolean.FALSE; } return check; } static int sizeOfList(SinglyLinkedListNode head) { int count = 0; while (head.next != null) { head = head.next; count++; } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Compare two linked lists
You are viewing a single comment's thread. Return to all comments →
This is my code. JAVA