Lecture 23: Doubly Linked List

Slides:



Advertisements
Similar presentations
1 Linked Lists Continued Lecture 5 Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists ADS2 Lecture 5.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
CSC 212 – Data Structures Lecture 13: Linked Lists.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
Building Java Programs Bonus Slides Hashing. 2 Recall: ADTs (11.1) abstract data type (ADT): A specification of a collection of data and the operations.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 8 Lists, Iterators, and Doubly Linked Lists.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
1 Today’s Material List ADT –Definition List ADT Implementation: LinkedList.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Marcus Frean.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 9 Doubly Linked Lists and Ordered Lists Lecture.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
1 CS162: Introduction to Computer Science II Abstract Data Types.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
Linked Data Structures
Lecture 6 of Computer Science II
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
4. Linked Lists.
Ch7. List and Iterator ADTs
Linked Lists Chapter 5 (continued)
CSE 116/504 – Intro. To Computer Science for Majors II
Heaps And Priority Queues
Sequences and Iterators
Introduction to Analysing Costs
CSE 116/504 – Intro. To Computer Science for Majors II
Lecture 15: More Iterators
CSE 116/504 – Intro. To Computer Science for Majors II
Programming Abstractions
Implementing ArrayList Part 1
Linked Lists head One downside of arrays is that they have a fixed size. To solve this problem of fixed size, we’ll relax the constraint that the.
LINKED LISTS CSCD Linked Lists.
Top Ten Words that Almost Rhyme with “Peas”
Heaps & Priority Queues
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Ch7. List and Iterator ADTs
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Arrays and Linked Lists
Programming in Java Lecture 11: ArrayList
" A list is only as strong as its weakest link. " - Donald Knuth
Linked Lists.
Programming Abstractions
Programming II (CS300) Chapter 07: Linked Lists and Iterators
CS2013 Lecture 4 John Hurley Cal State LA.
Lists CSE 373 Data Structures.
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Computer Science and Engineering
ArrayLists 22-Feb-19.
Collections Framework
CSE 143 Lecture 25 Set ADT implementation; hashing read 11.2
Linked Lists Chapter 5 (continued)
CSC 143 Java Linked Lists.
Data Structures & Algorithms
Lecture No.02 Data Structures Dr. Sohail Aslam
Recursive Objects Singly Linked Lists.
Lists CSE 373 Data Structures.
Building Java Programs
Programming II (CS300) Chapter 07: Linked Lists
Lecture 7: Linked List Basics reading: 16.2
TCSS 143, Autumn 2004 Lecture Notes
slides created by Marty Stepp
Linked Lists Chapter 5 (continued)
Problem Understanding
Presentation transcript:

Lecture 23: Doubly Linked List CSE 116/504 – Intro. To Computer Science for Majors II Lecture 23: Doubly Linked List

"Convince your neighbors" Announcements Lectures have typical pattern for adult learning Ask question (ungraded) "Convince your neighbors" Ask question (graded) May see input dialog in TopHat but no question on screen Ignore these questions; testing students paying attention Lose points for answering; me having some "fun" Public domain picture of the creepy clown. Original available at: https://pixabay.com/p-2836388/?no_redirect

What Can We Know About List? List interface defined in java.util package Specifies all of the methods we can call on a List Effect of each method included in these definition Also includes value returned & potential exceptions Start TopHat slide –do NOT show to class

List ADT Based upon a imagined resizable array Arbitrary sequence of elements stored within list List ADT keeps elements indexed from 0 to n-1 Index just int; gives absolute position in List 1 2 3 4 5

Linked List Nodes ("thingys") very limited in functionality Design splits Entry from List implementation Excellent OO design: each class focused on 1 job LinkedList head size  4 modCount  99 Advance TopHat slide – still do NOT show to class Entry Entry Entry Entry elem next elem next elem next elem next

1st Key Point for Linked Lists Linked list chain of Entrys Entry is linked list

2nd Key Point for Linked Lists Entry holds element Entry is element

List Methods boolean add(E e); void add(int i, E e); E set(int i, E e); boolean remove(Object o); E remove(int i); boolean contains(Object o); int indexOf(Object o); E get(int i); // size(),isEmpty(),iterator() & other boring ones

Linked lists use Entrys but List Method Issue Linked lists use Entrys but List interface specifies int boolean add(E e); void add(int i, E e); E set(int i, E e); boolean remove(Object o); E remove(int i); boolean contains(Object o); int indexOf(Object o); E get(int i); // size(),isEmpty(),iterator() & other boring ones

3rd Key Point for Linked Lists LinkedList is-a List Traverses Entrys to reach target

Fill in the Blank trav.getNext(); trav += 1; trav.getElement(); Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext(); 1

Convince neighbor your answer Fill in the Blank Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while Convince neighbor your answer is correct trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext();

Fill in the Blank trav.getNext(); trav += 1; trav.getElement(); Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext(); 1

Entry IS NOT index Fill in the Blank trav.getNext(); trav += 1; Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while Entry IS NOT index trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext();

Entry IS NOT element Fill in the Blank trav.getNext(); trav += 1; Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext(); Entry IS NOT element

Closer, but what happens to return value? Fill in the Blank Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while Closer, but what happens to return value? trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext();

trav never assigned to new alias! Fill in the Blank Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while Closer, but what happens to return value? trav never assigned to new alias! trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext();

trav never assigned to new alias! Fill in the Blank Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav never assigned to new alias! Return value goes: trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext();

Fill in the Blank trav.getNext(); trav += 1; trav.getElement(); Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext(); Gets next Entry in list

AND reassigns trav so it aliases next Node Fill in the Blank Entry<E> trav = head while (trav != null && !/* found node */) /* Update vars helping find node */ ___________________ end while trav.getNext(); trav += 1; trav.getElement(); trav = trav.getNext(); Gets next Entry in list AND reassigns trav so it aliases next Node

Traversal Algorithm Starts List method needing non-head nodes Entry<E> trav = head while (trav != null && ! /* found node */ ) /* Update vars helping find node */ trav = trav.getNext() end while /* Now use trav to complete method */

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) 1

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Convince neighbor your answer is correct Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1)

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) 1

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Big-Oh based on input size; linked list is input, so number of nodes = n Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1)

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) Big-Oh measures worst case; assume node not found

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) Does constant work

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) Does constant work for every node

Traversal's Big-Oh Complexity? Entry<E> trav = head while (trav != null && !/*found node*/) /* Update vars helping find node */ trav = trav.getNext() end while Impossible to know without the number of nodes in linked list O(n) Depends on where the needed node is O(1) Does constant work for every node in worst case

ArrayList v. LinkedList Method ArrayList LinkedList w/ tail remove(i) O(n) (generally) O(1) (if i=0) remove(e) O(n) contains(e) indexOf(e) get(i)/ set(i,e) O(1) (at either end) add(e) O(1) add(i,e)

Array-based List.remove(i) remove(i) "shifts" elements down to fill hole O(n) time required in the general case If i =size()-1, have special best case of O(1) time But must consider worst case when computing big-Oh 1 2 e n-1 i

Array-based List.add(i, e) add(i, e) "shifts" elements to make space in array When array fills, must allocate new array & copy over Time needed based on i – amount getting moved If adding to end, have best case of O(1) time O(n) general/worst case from shifting all elements 1 2 n-1 i

Array-based List.add(i, e) add(i, e) "shifts" elements to make space in array When array fills, must allocate new array & copy over Time needed based on i – amount getting moved If adding to end, have best case of O(n) time O(n) general/worst case from shifting all elements 1 2 n-1 i

Other List’s Methods remove() removes element IF in List already Requires comparing with elements currently in List contains() checks if element already included indexOf() returns first index or -1 if not in list get()/set() uses element at specific index No comparison required, just requires using array index

ArrayList v. LinkedList Method ArrayList LinkedList w/ tail remove(i) O(n) (generally) O(1) (if i=size-1) O(1) (if i=0) remove(e) O(n) contains(e) indexOf(e) get(i)/ set(i,e) O(1) O(1) (at either end) add(e) add(i,e)

ArrayList v. LinkedList Method ArrayList LinkedList w/ tail remove(i) O(n) (generally) O(1) (if i=size-1) O(1) (if i=0) remove(e) O(n) contains(e) indexOf(e) get(i)/ set(i,e) O(1) O(1) (at either end) add(e) add(i,e) O(1) (at either end)

Problem with Singly Linked tail improves performance at List's end add(e) like add(0,e) but uses tail rather head When head or tail used, get() & set() very quick remove() with tail slow; traverse to find prior node LinkedList head tail size  4 Entry Entry Entry Entry elem next elem next elem next elem next

Using Singly Linked List Nodes added & removed along with elements Unlike array-based List, limits demands on memory 1st and last element quick to add, retrieve, & update O(1) time makes linked list fastest removing 1st element Slowest removing last element needing full O(n) time

Using Singly Linked List Nodes added & removed along with elements Unlike array-based List, limits demands on memory 1st and last element quick to add, retrieve, & update O(1) time makes linked list fastest removing 1st element Slowest removing last element needing full O(n) time Means linked lists great when end elements used But not equally, add either end but only remove head

Using Singly Linked List Nodes added & removed along with elements Unlike array-based List, limits demands on memory 1st and last element quick to add, retrieve, & update O(1) time makes linked list fastest removing 1st element Slowest removing last element needing full O(n) time Means linked lists great when end elements used But not equally, add either end but only remove head

Doubly Linked List Link to previous node in list also in each node Each doubly-linked node contains: Element (data) reference Link to next Entry Prev(ious) Entry also linked elem Doubly-linked node next prev

Doubly Linked List Link to previous node in list also in each node Each doubly-linked node contains: Element (data) reference Link to next Entry Prev(ious) Entry also linked

Implementing Entry Doubly-linked node could extend Entry next & elem fields exist in both of these classes Only difference is prev field added for doubly-linked Allows mixing singly- & doubly-linked in same list But this is weird and would almost never happen Prevent this monstrosity! Do not use inheritance here

1st Entry Class (Singly-Linked) public class Entry<T> { private T element; private Entry<T> next; public Entry(T e, Entry<T> n) { element = e; next = n; } public T getElement() { return element; } public Entry<T> getNext() { return next; } // Rest of the getters and setters omitted because they are boring }

2nd Entry Class (Doubly-Linked) public class Entry<Bob> { private Bob element; private Entry<Bob> next, prev; public Entry(Bob e, Entry<Bob> n, Entry<Bob> p) { element = e; next = n; prev = p; } public Bob getElement() { return element; } public Entry<Bob> getNext() { return next; } public void setPrev(Entry<Bob> newPrev) { prev = newPrev; } // Rest of the getters and setters omitted because they are boring }

2nd Entry Class (Doubly-Linked) public class Entry<Bob> { private Bob element; private Entry<Bob> next, prev; public Entry(Bob e, Entry<Bob> n, Entry<Bob> p) { element = e; next = n; prev = p; } public Bob getElement() { return element; } public Entry<Bob> getNext() { return next; } public void setPrev(Entry<Bob> newPrev) { prev = newPrev; } // Rest of the getters and setters omitted because they are boring }

2nd Entry Class (Doubly-Linked) public class Entry<T> { private T element; private Entry<T> next, prev; public Entry(T e, Entry<T> n, Entry<T> p) { element = e; next = n; prev = p; } public T getElement() { return element; } public Entry<T> getNext() { return next; } public void setPrev(Entry<T> newPrev) { prev = newPrev; } // Rest of the getters and setters omitted because they are boring }

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); LinkedList head tail size  4 modCount  6

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); LinkedList head tail size  4 modCount  6

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; LinkedList head tail size  3 modCount  7

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; LinkedList head tail size  3 modCount  7

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; LinkedList head tail size  3 modCount  7

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; tail.setNext(null); LinkedList head tail size  3 modCount  7

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; tail.setNext(null); LinkedList head tail size  3 modCount  7

Removing the Tail Use Entry's prev field to get next-to-last Entry Avoids the O(n) traversal using O(1) field lookup Just set tail field in LinkedList class like this: tail = tail.getPrev(); size -= 1; modCount += 1; tail.setNext(null); LinkedList head tail size  3 modCount  7

Removing an Internal Node Linked list's length equals number of elements Requires unlinking Entry from linked list Nothing fancy needed, just adjust prev & next links Entry 0nly included because of links, so this does it all

Removing an Internal Node Requires unlinking Entry from linked list Nothing fancy needed, just adjust prev & next links Entry 0nly included because of links, so this does it all LinkedList head tail size  3 modCount 3

Removing an Internal Node Requires unlinking Entry from linked list Nothing fancy needed, just adjust prev & next links Entry 0nly included because of links, so this does it all LinkedList head tail size  3 modCount 3

Removing an Internal Node Requires unlinking Entry from linked list Nothing fancy needed, just adjust prev & next links Entry 0nly included because of links, so this does it all LinkedList head tail size  3 modCount 3

Removing an Internal Node Requires unlinking Entry from linked list Nothing fancy needed, just adjust prev & next links Entry 0nly included because of links, so this does it all LinkedList head tail size  2 modCount 4

Removing Internal Node public class LinkedList<T> implements List<T> { private Entry<T> head; private Entry<T> tail; private int size; private long modCount; private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow;

Removing Internal Node public class LinkedList<T> implements List<T> { private Entry<T> head; private Entry<T> tail; private int size; private long modCount; private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow;

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; LinkedList head tail size  2 modCount 4 prior

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; prior = removeMe.getPrev(); LinkedList head tail size  2 modCount 4 follow prior

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; prior = removeMe.getPrev(); follow = removeMe.getNext(); LinkedList head tail size  2 modCount 4 follow prior

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; prior = removeMe.getPrev(); follow = removeMe.getNext(); prior.setNext( ); LinkedList head tail size  2 modCount 4 follow prior

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; prior = removeMe.getPrev(); follow = removeMe.getNext(); prior.setNext(follow); follow.setPrev( ); LinkedList head tail size  2 modCount 4 follow prior

Removing Internal Node public class LinkedList<T> implements List<T> { /* More code exists, but removed for space */ private void removeInternalNode(Entry<T> removeMe) { Entry<T> prior, follow; prior = removeMe.getPrev(); follow = removeMe.getNext(); prior.setNext(follow); follow.setPrev(prior); size -= 1; modCount += 1; } LinkedList head tail size  2 modCount 4 follow prior

Coding is hard Drawing is easy Using drawings makes coding easier Programming Pro Tip Coding is hard Drawing is easy Using drawings makes coding easier

Almost Forgot Easy writing two of LinkedList boring methods size() -- returns size isEmpty() – returns if size is equal to 0 Easy start to third method since it has little work iterator() -- returns new LLIterator(); But now we must write LLIterator class

Almost Forgot Easy writing two of LinkedList boring methods size() -- returns size isEmpty() – returns if size is equal to 0 Easy start to third method since it has little work iterator() -- returns new LLIterator(); But now we must write LLIterator class

But Not That Much Work

Type of LLIterator's Cursor?

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int 18

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int Convince neighbor your answer is correct

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int 1

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int Cursor used to access elements; cannot use element to access elements

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int

Best LLIterator Cursor Type? LLIterator lacks array, so no cursor is required T (the element type) Entry (the node type) int Cursor used to access elements; in a linked list, we use nodes to hold & access elements

Last Linked List Key Concept Entry in LLIterator equivalent to index in ArrayListIterator

Final LLIterator Details if cursor will access a valid location value at cursor’s location Advance cursor to refer to next location if (cursor != null) cursor.getElement() cursor.getNext()

Final LLIterator Details if cursor will access a valid location value at cursor’s location Advance cursor to refer to next location if (cursor != null) cursor.getElement() cursor.getNext()* * If you are not objecting, today's 1st TopHat failed

Final LLIterator Details if cursor will access a valid location value at cursor’s location Advance cursor to refer to next location if (cursor != null) cursor.getElement() cursor = cursor.getNext()

Does Absolute Position Matter?

Nodes Help With Relative Order

ArrayList v. LinkedList Method ArrayList LinkedList w/ tail remove(i,e) O(n) (generally) O(1) (if i=size-1) O(1) (if i=0) remove(e) O(n) contains(e) indexOf(e) get(i)/ set(i,e) O(1) O(1) (at either end) add(e) add(i,e) O(1) (at either end)

1st Key Point for Linked Lists Linked list chain of Entrys Entry is linked list

2nd Key Point for Linked Lists Entry holds element Entry is element

Linked lists use Entrys but List Method Issue Linked lists use Entrys but List interface specifies int boolean add(E e); void add(int i, E e); E set(int i, E e); boolean remove(Object o); E remove(int i); boolean contains(Object o); int indexOf(Object o); E get(int i); // size(),isEmpty(),iterator() & other boring ones

Last Linked List Key Concept Entry in LinkListIterator equivalent to index in ArrayListIterator

3rd Key Point for Linked Lists LinkedList is-a List Traverses Entrys to reach target

Traversal Algorithm Starts List method needing non-head nodes Entry<E> trav = head while (trav != null && ! /* found node */ ) /* Update vars helping find node */ trav = trav.getNext() end while /* Now use trav to complete method */

Coding is hard Drawing is easy Using drawings makes coding easier Programming Pro Tip Coding is hard Drawing is easy Using drawings makes coding easier

For Next Lecture Monday reviews material from midterm What are your questions from this midterm? What was your grade and can you see results? Were the Tim Hertz-tons questions from real world? Week #8 assignment available & due on Monday Can finish assignment now & relax this weekend! Phase #2 due in 10 days – make sure group is ready