My assignment is supposed to be implementing certain methods from list and linkedlist, using a singly linked list (nodes).
I was wondering how would I implement the equals method and hashcode method using this, the equals method compares two lists, but I'm not sure how that translates into the nodes, does it create two lists of nodes? Or does one go after the other and how would I go about creating the method that tests for equality?
public class List12 implements java.util.List {
private Node head;
private int size;
private class Node{
T data;
Node next;
Node previous;
Node(T data){
this.data = data;
}
public Node(){
this.data = null;
this.next = null;
}
public Node(T data, Node<T> next){
this.data = data;
this.next = next;
}
public T getData(){
return data;
}
public void setData(T data){
this.data = data;
}
public Node<T> getNext(){
return next;
}
public void setNext(Node<T> next){
this.next = next;
}
}
public void removeNode(Node node){
if(size == 0)
head = null;
else{
if(node == head){
head = node.next;
node.next.previous = null;
}
else{
node.next.previous = node.previous;
node.previous.next = node.next;
}
}
size--;
}
public Node findNode(int index){
Node myNode;
myNode = head;
while( index-- > 0)
myNode = myNode.next;
return myNode;
}
public List12() {
head = null;
size = 0;
}
That's just the code for my nodes and its methods, I've implemented the other methods but I have no idea for the equal and hashcode method. Thanks for any help.