



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1
Typical List Implementation
2
Cool List Implementation Trick
You must practice this technique if you expect to use it
head is never null, even for an empty list
head is set to first node when list is created
head is never changed the value of the first node isn’t ever looked at
Class List { // value of first Node isn’t part of list final Node head = new Node(null); }
Insert in Front of i’th Element
void insertInFrontOf(int pos, Object value) {
Node after = head; for(int i = 0; i < pos; i++) after = after.next; Node newNode = new Node(value, after.next); after.next = newNode;
}