1. Engineering
  2. Computer Science
  3. implement a recursive method called duplist that takes the first...

Question: implement a recursive method called duplist that takes the first...

Question details

Implement a recursive method called dupList that takes the first node in a singly linked list and returns a new copy of the list. For example, if dupList is called or containing (10, 5), (40, 32), (13, 37). A sample implementation for a node of a singly linked list is given below - your method must be in terms of it. You may not use any calls.

public class Point2DNode {

private Point2DNode next;

private final int x;

private final int y;

public Point2DNode(int x, int y) {

next = null;

this.x = x;

this.y = y;

}

public Point2DNode getNext() {

return next;

}

public void setNext(Point2DNode node) {

next = node;

}

public T getX() {

return x;

}

public T getY() {

return y;

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution