class Node{ Type * content Node * next } class LinkedList{ Node * head Node * tail // easier } ---------------------------- class LinkedList{ Node * head Node * tail void printList() { Node * current = head while (current != null){ print(current.content) current = current.next } } } ---------------------------- class LinkedList{ Node * head Node * tail void add(Type * newElement){ Node * newNode = new Node newNode.content = newElement if (head == null) { head = newNode tail = newNode } else{ tail.next = newNode tail = newNode } } } ---------------------------- class LinkedList{ Node * head Node * tail Type * removeFirst(){ if (head == null) { return null } else { Type * result = head.content if (head == tail) { tail = null } head = head.next return content } } } ---------------------------- class BookNode{ Book * content Node * next } 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 } // when we are up to pos if (i == pos AND current != null) { // special case: it was the first node if (prev == null) { head = head.next } else{ // splice out the current node prev.next = current.next } // special case: it was the last node if (tail == current){ tail = prev } return current.content } //B if we hit end of the list before pos, no such node return null } }