Skip to content

Commit 61e952a

Browse files
authored
Create 3.Compare two Linked Lists
adding functionality method
1 parent 4349aa5 commit 61e952a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

3.Compare two Linked Lists

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {
2+
3+
boolean isEqual=false;
4+
5+
while(head1!=null && head2!=null){
6+
7+
if(head1.data==head2.data){
8+
9+
head1=head1.next;
10+
head2=head2.next;
11+
12+
}
13+
else{
14+
15+
return isEqual;
16+
}
17+
}
18+
19+
if((head1==null && head2!=null)||(head2==null && head1!=null)){
20+
return isEqual;
21+
}
22+
23+
isEqual=true;
24+
return isEqual;
25+
26+
27+
28+
}

0 commit comments

Comments
 (0)