CS-2851 Dr. Mark L. Hornick 1 Linked-List collections Structure and Implementation.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Stacks, Queues, and Linked Lists
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
Linked Lists Linear collections.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Linked Lists Course Lecture Slides 23 July 2010 A list is only as strong.
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
Chapter 6.5, 17 Linked Lists 1CSCI 3333 Data Structures.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chapter 6 Linked Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Lists Based on content from: Java Foundations, 3rd Edition.
The Java Collections Framework (JCF) Introduction and review 1.
LISTS Slides of K. Birman, Cornell University. List Overview 2  Purpose  Maintain an ordered collection of elements (with possible duplication)  Common.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Lists and Iterators Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming.
COM S 228 Collections and Iterators Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff 201.
Copyright © 0 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
List Interface and Linked List Mrs. Furman March 25, 2010.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Lab - 11 Keerthi Nelaturu. Ordered Structure Using Doubly linked list All elements in the list are arranged in an order Implement the Ordered Structure.
Lecture 9: Lists MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture we will learn…. ArrayList – These are re-sizeable.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
CS-2852 Data Structures LECTURE 5 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
CSE 501N Fall ‘09 10: Introduction to Collections and Linked Lists 29 September 2009 Nick Leidenfrost.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
CS-2852 Data Structures Week 4, Class 1 - Review Review! Thursday Exam I - Review Implementing ArrayList Big-O Iterators – High-level description Linked.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Standard Template Library
Week 4 - Monday CS221.
Abstraction A tool (concept) to manage complexity
University of Central Florida COP 3330 Object Oriented Programming
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Arrays and Collections
Binary Trees CS-2851 Dr. Mark L. Hornick.
Computer Science and Engineering
Collections Framework
Lecture 16 Section 6.2 Thu, Mar 1, 2007
JCF Collection classes and interfaces
Programming II (CS300) Chapter 07: Linked Lists
Chapter 9 Linked Lists.
Presentation transcript:

CS-2851 Dr. Mark L. Hornick 1 Linked-List collections Structure and Implementation

CS-2851 Dr. Mark L. Hornick 2 The JCF LinkedList class… implements the List interface along with Cloneable, Iterable, Collection … extends AbstractList & AbstractCollection Just like ArrayList So what’s different???

CS-2851 Dr. Mark L. Hornick 3 Analysis: SinglyLinkedList class Read the text! The SinglyLinkedList class (partially) implements a singly linked list An example class – not the real JCF implementation Purpose in book: to introduce the mechanisms of links Without the full complexity of JCF’s LinkedList

CS-2851 Dr. Mark L. Hornick 4 SinglyLinkedList structural implementation Each E element is contained in an Entry object Entry is a nested class contained by SinglyLinkedList class Each Entry is an object that: includes a reference, called a link, to another Entry object Entry contains a field of type E

CS-2851 Dr. Mark L. Hornick 5 SinglyLinkedList with 0 entries head SinglyLinkedList null size =0

CS-2851 Dr. Mark L. Hornick 6 Singly Linked List with 1 entry head SinglyLinkedList Element ref Entry next null For each Entry object, the link is to the Entry object that contains the next element in the collection… …except the one that holds the last element in the collection, which contains a null reference size =1

CS-2851 Dr. Mark L. Hornick 7 Singly Linked List with 4 entries head SinglyLinkedList Element ref Entry next Element ref Entry next Element ref Entry next Element ref Entry next null For each Entry object, the link is to the Entry object that contains the next element in the collection… …except the one that holds the last element in the collection, which contains a null reference size =4

CS-2851 Dr. Mark L. Hornick 8 Doubly-Linked Lists Each Entry object except the first also includes a link to the Entry object that contains the previous element. JCF LinkedList is a Doubly-linked list The Java Collections Framework’s implementation of the LinkedList class stores the elements in a circular, doubly-linked structure of Entry objects.

CS-2851 Dr. Mark L. Hornick 9 Doubly Linked List with no entries tail head DoublyLinkedList null size =0

CS-2851 Dr. Mark L. Hornick 10 Doubly Linked List with 1 entry tail head DoublyLinkedList prev Element ref Entry next null size =1

CS-2851 Dr. Mark L. Hornick 11 Doubly Linked List with 4 entries tail head DoublyLinkedList prev Element ref Entry next prev Element ref Entry next prev Element ref Entry next prev Element ref Entry next null size =4

CS-2851 Dr. Mark L. Hornick 12 Group Activity/Demo Implement SinglyLinkedList SinglyLinkedList () add( E o ) clear() get( int index ) remove( int index ) size() Read LinkedList javadoc for description of behavior at

CS-2851 Dr. Mark L. Hornick 13 LinkedList vs. ArrayList Advantages Flexible storage Grows/shrinks easier (faster) Disadvantages Access time Loss of (true) indexing, thus more expensive to implement indexing Because storage is non-contiguous LinkedList objects lack the (fast) random-access ability of ArrayList objects (due to slow indexing) Access must be done via iteration from the end of the list (either front or back) to the target – thus slower Storage overhead is higher due to Entry objects