This may be a dumb question as I am not majoring in the computer. I am reading Cracking the coding interview and it has the following codes.
But Java (in eclipse) cannot recognize LinkedListNode
but it recognize LinkedList
.
Am I supposed to create a class name LinkedListNode
, a double linked list? Shouldn't java already have that in import java.util.*
as it does for LinkedList
?
import java.util.*;
public static void deleteDups2(LinkedListNode head) {
if (head == null) return;
LinkedListNode previous = head;
LinkedListNode current = previous.next;
while (current != null) {
LinkedListNode runner = head;
while (runner != current) { // Check for earlier dups
if (runner.data == current.data) {
LinkedListNode tmp = current.next; // remove current
previous.next = tmp;
current = tmp; // update current to next node
break; // all other dups have already been removed
}
runner = runner.next;
}
if (runner == current) { // current not updated - update now
previous = current;
current = current.next;
}
}
}
next
. Not even providing a definition for what the LinkedListNode class actually is. I cant find a definition of it online. Seems like they slapped this together from one language and translated to another assuming the user would know what it is. Had this been an actual interview question I would just have just incremented the pointer and told the interviewer that its an unknown class.