class Node Type * content Node * next end Node class LinkedList Node * head Node * tail // easier end LinkedList ---------------------------- class LinkedList Node * head Node * tail void print() Node * current = head while (current != null) print current.content current = current.next end while end print end LinkedList ---------------------------- class LinkedList Node * head Node * tail void add(Type * newElement) Node * newNode = new Node newNode.content = newElement if (head == null) then head = newNode tail = newNode else tail.next = newNode tail = newNode end if end add end LinkedList ---------------------------- class LinkedList Node * head Node * tail Type * removeFirst() if (head == null) then return null else Type * result = head.content if (head == tail) then tail = null endif head = head.next return content end if end add end LinkedList ---------------------------- class BookNode Book * content Node * next end BookNode class BookList BookNode * head BookNode * tail Book * remove(int pos) BookNode * current = head // need to hold onto previous node // so we can set its next BookNode * prev = null // loop to the pos position, but stop if we run out of nodes // could use while or for, either way, need AND for (int i = 0; i < pos AND current != null; i = i + 1) prev = current current = current.next end for // when we are up to pos if (i == pos AND current != null) then // special case: it was the first node if (prev == null) then head = head.next else // splice out the current node prev.next = current.next endif // special case: it was the last node if (tail == current) tail = prev endif return current.content endif //B if we hit end of the list before pos, no such node return null end remove end LinkedList