Question: Write a method that takes in 2 heads of 2 linked lists and compares the 2 lists according to the following: 1) Return false if

Write a method that takes in 2 heads of 2 linked lists and compares the 2 lists according to the following:

1) Return false if the number of elements of the lists are different, otherwise go to 2

2) Return true if the two lists have the same exact elements in the same exact order, false otherwise.

Given: public class Node{

public int value;

public Node next;

public Node (int v, Node n) {value = v; next n;}

Complete the following code:

public boolean areEqual (Node head1, Node head2) {

Node cursor1 = head1, cursor2 = head2;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!