public class LinkedList {
Node head = null;
Node tail = null;
int length = 0;
public void add(Object object) {
Node node = new Node(object, null);
if (head == null) {
head = tail = node;
}
tail.setNext(node);
tail = node;
length++;
}
public int length() {
return length;
}
}
public class Node {
private Object data;
private Node next;
public Node(Object data, Node next) {
super();
this.data = data;
this.next = next;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}