CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008
Today More on Lists –Doubly Linked –Circular
Linked Lists Three classes (typically) working together –an “item” class one atomic unit of the aggregate data e.g., a “Name” class (item) might have two instance variables String first, last; –a “node” class one “item” and a reference to the next “node” the next reference is the “link” in “linked list” –a “list” class reference to the first “node”—head of the list
Linked Lists Add(int i, E o) Node List head Node
Linked Lists Remove(int i) List head Node
Problem: in class Assume each Node contains a Double (accessible with.value(). Write the insert method if the list is already in order and is to remain in order.
Singly-Linked List Speed: –Remove/add to front is constant time –Remove/add to back or middle is O(n) How to make constant for addLast? Doubly Linked List. –Each node references both next and previous –Data member tail references last element, to improve add/remove last.
addLast removeLast
Circular Linked List No head, only tail. tail.next is head. What does addFirst look like? addLast Others?