Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008.

Similar presentations


Presentation on theme: "CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008."— Presentation transcript:

1 CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008

2 Today More on Lists –Doubly Linked –Circular

3 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

4 Linked Lists Add(int i, E o) Node List head Node

5 Linked Lists Remove(int i) List head Node

6 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.

7 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.

8 addLast removeLast

9 Circular Linked List No head, only tail. tail.next is head. What does addFirst look like? addLast Others?


Download ppt "CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008."

Similar presentations


Ads by Google