Docsity

Linked List Implementation - Lecture Slides | CSSE 220, Exams of Computer Science

Partial preview of the text

Download Linked List Implementation - Lecture Slides | CSSE 220 and more Exams Computer Science in PDF only on Docsity!

LinkedList Implementation

`^

Turn in your written problems

`^

Reminder: Exam #2 is 1 week from today

`^

Markov Progress:^ ◦^

Milestone 1 official due time Tuesday 8:05 AM ◦^

But you should think of the real due time as Saturdayat noon, so you can make progress on Milestone 2this weekend. `^

Questions: Data structures? Markov?

`^

Today: LinkedList implementation

`^

If you missed zero or one classes, the startingpoint for your grade is 2.

`^

Plusses: regular class participation, asking andanswering questions, working well with others onin-class pair projects, posting to the discussionforums (especially if you answer other studentsquestions), many bug reports, assisting otherstudents, making suggestions for courseimprovement, etc..

`^

Minuses:

Missing more than one class

(unexcused), being late a lot, not "being there"when I have asked you questions in class, notworking well with your partners on projects, notsubmitting partner evaluations.

`^

Stores items (non-contiguously) in nodes; eachcontains a reference to the next node.

`^

Lookup by index is linear time (worst, average).

`^

Insertion or removal is constant time once we havefound the location.^ ◦^

show how to insert A4 after A1. `^

If

Comparable

list items are kept in sorted order,

finding an item still takes linear time.

class ListNode{

Object element;

// contents of this node

ListNode next;

// link to next node

ListNode (Object element,

ListNode next) {

this.element = element;this.next = next; } ListNode (Object element) {

this(element, null); } ListNode () {

this(null); } }

How to implement

LinkedList? fields?Constructors?Methods?

`^

More specifically, what is a j

ava.util.Iterator

?

◦^

It's an interface: ◦^

interface

java.util.Iterator

◦^

with the following methods:

An extension,

ListIterator

, adds: