Methods Summary |
---|
public synchronized LinkedList$Linkable | getHead()Return the first node in the list return head;
|
public synchronized void | insertAtHead(LinkedList$Linkable node)Insert a node at the beginning of the list
node.setNext(head);
head = node;
|
public synchronized void | insertAtTail(LinkedList$Linkable node)Insert a node at the end of the list
if (head == null) head = node;
else {
Linkable p, q;
for(p = head; (q = p.getNext()) != null; p = q);
p.setNext(node);
}
|
public synchronized void | remove(LinkedList$Linkable node)Remove a node matching the specified node from the list.
Use equals() instead of == to test for a matched node.
if (head == null) return;
if (node.equals(head)) {
head = head.getNext();
return;
}
Linkable p = head, q = null;
while((q = p.getNext()) != null) {
if (node.equals(q)) {
p.setNext(q.getNext());
return;
}
p = q;
}
|
public synchronized LinkedList$Linkable | removeFromHead()Remove and return the node at the head of the list
Linkable node = head;
if (node != null) {
head = node.getNext();
node.setNext(null);
}
return node;
|
public synchronized LinkedList$Linkable | removeFromTail()Remove and return the node at the end of the list
if (head == null) return null;
Linkable p = head, q = null, next = head.getNext();
if (next == null) {
head = null;
return p;
}
while((next = p.getNext()) != null) {
q = p;
p = next;
}
q.setNext(null);
return p;
|