Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.

Slides:



Advertisements
Similar presentations
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advertisements

List Implementations That Use Arrays
Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Designing an ADT The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT What data does.
An Array-Based Implementation of the ADT List public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object.
Abstract Data Types. Typical operations on data  Add data to a data collection  Remove data from a data collection  Ask questions about the data in.
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
List Implementations That Use Arrays Chapter 5 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
Iterators Chapter 7. Chapter Contents What is an Iterator? A Basic Iterator Visits every item in a collection Knows if it has visited all items Doesn’t.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
List Implementations That Link Data Chapter 6. 2 Chapter Contents Linked Data Forming a Chains The Class Node A Linked Implementation Adding to End of.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary A Java Interface Iterators Using the ADT Dictionary A Directory of Telephone.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Chapter 3 Introduction to Collections – Stacks Modified
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 ArrayList  Array’s are limited because we need to know the size before we use them.  An ArrayList is an extension of an array that grows and shrinks.
ArrayList, Multidimensional Arrays
Lists Ellen Walker CPSC 201 Data Structures Hiram College.
Data Structures and Abstractions with Java, 4e Frank Carrano
Abstract Data Types. What’s on the menu? What’s an abstract data type? How do you implement it? ADT List.
1 Stacks. 2 A stack has the property that the last item placed on the stack will be the first item removed Commonly referred to as last-in, first-out,
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
 A Collection class is a data type that is capable of holding a group of items.  In Java, Collection classes can be implemented as a class, along with.
April 24, 2017 Chapter 4 Data Abstraction The Walls
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
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.
Object Oriented Programming in Java Habib Rostami Lecture 7.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
Lists and Sorted Lists: various implementations Slides by Nadia Al-Ghreimil adopted from Steve Armstrong LeTourneau University Longview, TX  2007, 
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
1 CS162: Introduction to Computer Science II Abstract Data Types.
An Array-Based Implementation of the ADT List
Sections 3.4 Formal Specification
Lists Chapter 4.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Implementing ArrayList Part 1
Java collections library
Data Abstraction A technique for increasing the modularity of a program The need to support several operations on the data arise need to define abstract.
TCSS 143, Autumn 2004 Lecture Notes
Priority Queues.
Programming in Java Lecture 11: ArrayList
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Adapted from Pearson Education, Inc.
EE 422C Sets.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Lists Chapter 8.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Programming II (CS300) Chapter 07: Linked Lists
Recitation 2 CS0445 Data Structures
Java Generics & Iterators
Copyright ©2012 by Pearson Education, Inc. All rights reserved
A List Implementation that Uses An Array
© 2016 Pearson Education, Ltd. All rights reserved.
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Lists Chapter 4

2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface List Using a List Is Like Using a Vending Machine

3 Specifications for the ADT List A list provides a way to organize data Fig. 4-1 A to-do list.

4 Specifications for the ADT List Operations on lists Add new entry – at end, or anywhere Remove an item Remove all items Replace an entry Look at any entry Look for an entry of a specific value Count how many entries Check if list is empty, full Display all the entries

5 Specifications for the ADT List To specify an ADT list Describe its data Specify the operations ADT list must be considered in general Not necessarily a list of strings Note specification, page 83, 84

6 Example Fig. 4-2 The effect of ADT list operations on an initially empty list

7 Potential Problem Operations add, remove, replace, getEntry work OK when valid position given remove, replace and getEntry not meaningful on empty lists A list could become full, what happens to add ?

8 Possible Solutions Assume the invalid situations will not occur Ignore the invalid situations Make reasonable assumptions, act in predictable way Return boolean value indicating success or failure of the operation Throw an exception

9 Redefining Specifications A first draft of an ADT specifications may ignore potential problems Simplifies the first draft Concentrate on details after major portions of specifications written Makes the specifications complete After writing specifications, implementations Write Java statements to use the ADT Checks understanding, suitability of the specifications

10 Using the ADT List Fig. 4-3 A list of numbers that identify runners in the order in which they finish a race

11 Using the ADT List AList implements interface ListInterface pg. 88, 89 of text. public class ListClient { public static void main(String[] args) { testList(); } // end main public static void testList() { ListInterface runnerList = new AList(); // has only methods // in ListInterface runnerList.add("16"); // winner runnerList.add(" 4"); // second place runnerList.add("33"); // third place runnerList.add("27"); // fourth place runnerList.display(); } // end testList } // end ListClient

12 Java Class Library: The Interface List The standard package contains a list interface – called List Methods provided public boolean add(Object newEntry) public void add(int index, Object newEntry) public Object remove(int index) public void clear() public Object set(int index, Object anEntry) // like replace public Object get(int index) // like getEntry public boolean contains(Object anEntry) public int size() // like getLength public boolean isEmpty()

13 A List is Like a Vending Machine Fig 4-4 A vending machine.

14 A List is Like a Vending Machine Observations about vending machines Can perform only tasks shown on interface Must understand the tasks Cannot see inside the machine Can use the machine even though don’t know what happens inside If inside of machine replaced with new improved version Interface remains unchanged Customer uses machine in same way as before

15 A List is Like a Vending Machine Observations about clients and List ADT Client can perform only operations from the ADT List Client must adhere to specifications Client cannot access data without an ADT operation Client can use the list – even though unable to access entries directly If implementation is changed, client still uses list in same way as before