I need to write a method that works based on the question provided, thanks... Pr
ID: 3606141 • Letter: I
Question
I need to write a method that works based on the question provided, thanks...
Problem 3 (10 points) The class DList implements a generic d provides the following methods. oubly linked list of nodes (with type DNode) and public class DList C // has instance variables and standard methods with titles public DList) public int size) // implementation not shown // implementation not shown // implementation not shown // implementation not shown // implementation not shown public boolean isEmpty ) public DNode getFirst) throws Exception public DNode getLast ) throws Exception public DNode getNext (DNodeExplanation / Answer
public class DList {
DNode MergeLists(DNode first, DNode second) {
DNode result = null, a = first, b = second;
/* point to the last result pointer */
DNode lastResultPtr = result;
while (true) {
if (a == null) {
lastResultPtr = b;
break;
} else if (b == null) {
lastResultPtr = a;
break;
}
if (a.getData() <= b.getData()) {
lastResultPtr.setNext(a);
a.setPrev(lastResultPtr);
a = a.getNext();
} else {
lastResultPtr.setNext(b);
b.setPrev(lastResultPtr);
b = b.getNext();
}
if (result == null)
result = lastResultPtr;
lastResultPtr = lastResultPtr.getNext();
}
return (result);
}
}
class DNode {
DNode next;
DNode prev;
Integer data;
public DNode getNext() {
return next;
}
public void setNext(DNode next) {
this.next = next;
}
public DNode getPrev() {
return prev;
}
public void setPrev(DNode prev) {
this.prev = prev;
}
public Integer getData() {
return data;
}
public void setData(Integer data) {
this.data = data;
}
}