Linked List Implementation CSSE 221 Fundamentals of Software - - PowerPoint PPT Presentation

linked list implementation
SMART_READER_LITE
LIVE PREVIEW

Linked List Implementation CSSE 221 Fundamentals of Software - - PowerPoint PPT Presentation

Linked List Implementation CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Announcements Checkout the SinglyLinkedList project from your individual SVN repository. Final Exam Wednesday evening,


slide-1
SLIDE 1

Linked List Implementation

CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

slide-2
SLIDE 2

Announcements

  • Checkout the SinglyLinkedList project from

your individual SVN repository.

  • Final Exam Wednesday evening,

– 6 pm to 10 pm, O157 (Sec 1) & O159 (Sec 2) – Start organizing your questions!

slide-3
SLIDE 3
  • Basic version:

– The LinkedList class has only 2 fields: a reference to the first node a reference to the last node – Each node keeps track of the next node in the list.

Linked List Basics

slide-4
SLIDE 4
  • What if we have to add/remove data from a

list frequently?

  • LinkedLists support this:

– Fast insertion and removal of elements

  • Once we know where they go

– Slow access to arbitrary elements

Another List Data Structure

data data data data data

null

Insertion, per Wikipedia

“random access”

slide-5
SLIDE 5
  • boolean add(T element)
  • void add(int index, T element)
  • int size()
  • boolean contains(T element)
  • boolean remove(T element)
  • T get(int index)
  • int indexOf(T element)
  • T set(int index, T element)
  • What about traversing the linked list?

– LinkedList<T> implements Iterable<T>

LinkedList<T> Methods

slide-6
SLIDE 6

Traversing the LinkedList

slide-7
SLIDE 7
  • A simplified version, with just the essentials
  • Won’t implement all of the java.util.List

interface

  • Will have the usual linked list behavior

– Fast insertion and removal of elements

  • Once we know where they go

– Slow random access

Implementing LinkedList

slide-8
SLIDE 8

Break

  • http://xkcd.com/379/

Of course, the assert doesn't work.