ITEC200 Week04 Lists and the Collection Interface.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Chapter 25 Lists, Stacks, Queues, and Priority Queues
Advanced Piloting Cruise Plot.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Introduction to Computation and Problem
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Chapter 17 Linked Lists.
Topic 12 The List ADT. 9-2 Objectives Examine list processing and various ordering techniques Define a list abstract data type Examine various list implementations.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
Linked Lists Chapter 4.
List Implementations That Use Arrays
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Data Structures Using C++
Double-Linked Lists and Circular Lists
John Hurley Cal State LA
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
1 Joe Meehean. Ordered collection of items Not necessarily sorted 0-index (first item is item 0) Abstraction 2 Item 0 Item 1 Item 2 … Item N.
ABC Technology Project
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Hash Tables,
VOORBLAD.
Review Pseudo Code Basic elements of Pseudo code
The List ADT Textbook Sections
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
ITEC200 Week10 Sorting. pdp 2 Learning Objectives – Week10 Sorting (Chapter10) By working through this chapter, students should: Learn.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
25 seconds left…...
Chapter 9: Data Structures I
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Chapter 11 Component-Level Design
Chapter 14 Introduction to Collections
Abstract Class, Packages and interface from Chapter 9
1 Abstract Class and Packages from Chapter 9 Lecture.
COMP 121 Week 11: Linked Lists. Objectives Understand how single-, double-, and circular-linked list data structures are implemented Understand the LinkedList.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
ITEC200 – Week03 Inheritance and Class Hierarchies.
ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type.
ITEC200 Week05 Stacks. 2 Learning Objectives – Week05 Stacks (Chapter05) Students can Use the methods provided in the public interface.
Sets and Maps ITEC200 – Week Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn.
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 Lists and the Collection Interface Chapter 4.
Lists and the Collection Interface Review inheritance & collections.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
COMP 121 Week 11: Linked Lists.
COMP 121 Week 8: Generic Collections. Objectives To understand type variables and how they are used in generic programming To be able to implement and.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
COMP 121 Week 9: ArrayList.
Lists and the Collection Interface
Presentation transcript:

ITEC200 Week04 Lists and the Collection Interface

2 Learning Objectives Week04 Lists and the Collection Interface (Ch4) Students can Explain the difference between various types of List structures (ArrayList, LinkedList) and their representation in the Java Utilise List operations to maintain lists of information Analyse implementations (both the approach to programming and the corresponding efficiency) of various kinds of Lists (eg, array based, single-, double-, and circular linked) Program augmentations to list implementations Explain the mechanics of the Iterator interface, analyse implementations of iterators and augment them according to specifications provided Describe the features of the Java Collection framework in relation to data structures Apply Java 5.0 generics to the implementation of Lists

3 The ArrayList Class An ArrayList is an Abstract Data Type for storing lists of data. Improvement over an array object Implements the List interface

4 The List Interface

5 Generic Collections Language feature introduced in Java 5.0 called generic collections (or generics) Generics allow you to define a collection that contains references to objects of a specific type List myList = new ArrayList (); specifies that myList is a List of String where String is a type parameter Only references to objects of type String can be stored in myList, and all items retrieved would be of type String. A type parameter is analogous to a method parameter.

6 Creating a Generic Collection

7 Specification of the ArrayList Class

8 Implementation of an ArrayList Class KWArrayList: simple implementation of a ArrayList class –Physical size of array indicated by data field capacity –Number of data items indicated by the data field size

9 Implementation of an ArrayList Class (continued)

10 The Vector Class Initial release of Java API contained the Vector class which has similar functionality to the ArrayList –Both contain the same methods New applications should use ArrayList rather than Vector Stack is a subclass of Vector

11 Single-Linked Lists and Double- Linked Lists The ArrayList: add and remove methods operate in linear time because they require a loop to shift elements in the underlying array A Linked list consists of a set of nodes, each of which contains its data and a reference to the next node Linked list overcomes this by providing ability to add or remove items anywhere in the list in constant time Each element (node) in a linked list stores information and a link to the next, and optionally previous, node

12 A List Node A node contains a data item and one or more links A link is a reference to a node A node is generally defined inside of another class, making it an inner class The details of a node should be kept private

13 Single-Linked Lists

14 Double-Linked Lists Limitations of a single-linked list include: –Insertion at the front of the list is O(1). –Insertion at other positions is O(n) where n is the size of the list. –Can insert a node only after a referenced node –Can remove a node only if we have a reference to its predecessor node –Can traverse the list only in the forward direction Above limitations removed by adding a reference in each node to the previous node (double-linked list)

15 Double-Linked Lists (continued)

16 Circular Lists Circular-linked list: link the last node of a double-linked list to the first node and the first to the last

17 The LinkedList Class Part of the Java API Implements List interface using a double-linked list

18 The Iterator Interface The List interface declares the method iterator, which returns an Iterator object that will iterate over the elements of that list The interface Iterator is defined as part of API package java.util An Iterator does not refer to or point to a particular node at any given time but points between nodes

19 The Iterator Interface (continued)

20 The ListIterator Interface Iterator has limitations ListIterator is an extension of the Iterator interface for overcoming these limitations Iterator should be thought of as being positioned between elements of the linked list

21 The ListIterator Interface (continued)

22 The Enhanced for Statement

23 The Iterable Interface This interface requires only that a class that implements it provide an iterator method The Collection interface extends the Iterable interface, so all classes that implement the List interface (a subinterface of Collection) must provide an iterator method

24 Implementation of a Double- Linked List

25 Implementation of a Double- Linked List (continued)

26 Application of the LinkedList Class Case study that uses the Java LinkedList class to solve a common problem: maintaining an ordered list

27 Application of the LinkedList Class (continued)

28 The Collection interface Collection interface specifies a set of common methods Fundamental features include: –Collections grow as needed –Collections hold references to objects –Collections have at least two constructors

29 The Collection Hierarchy

30 Where to from here… Work through Chapter 4 of the Koffman & Wolfgang Text Conceptual Questions and Practical Exercises Submit all preliminary work Be prompt for your online class

31 Acknowledgements These slides were based upon the Objects, Abstraction, Data Structures and Design using Java Version 5.0 Chapter 4 PowerPoint presentation by Elliot B. Koffman and Paul A. T. Wolfgang