CS 280 Data Structures Professor John Peterson. Project 9 Questions? IS280.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
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.
CS18000: Problem Solving and Object-Oriented Programming.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
Computer Science 209 Software Development Iterators.
Bag implementation Add(T item) – Enlarge bag if necessary; allocate larger array Remove(T item) – Reduce bag if necessary; allocate smaller array Iterator.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
CS 307 Fundamentals of Computer Science 1 Lists and ArrayList many slides taken from Mike Scott, UT Austin.
Tirgul OOP No.3 Iterators. What is an Iterator? An object that provides a way to access elements of an aggregate object sequentially, without exposing.
1 Topic 8 Iterators "First things first, but not necessarily in that order " -Dr. Who.
CS 280 Data Structures Professor John Peterson. Example 5 null 7 ab Link Data.
CS 307 Fundamentals of Computer ScienceIterators 1 Topic 14 Iterators "First things first, but not necessarily in that order " -Dr. Who.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Iterators CS 367 – Introduction to Data Structures.
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
08 1 Abstract Data Types Problem Sets: PS2 due due Monday, Feburary 26 PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 08 Monday, February 26.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Goals for Today  implement a Deck of Cards  composition  Iterator interface  Iterable interface 1.
CSC 142 J(part 1) 1 CSC 142 The ArrayList class [Reading: chapter 10]
Stacks and Queues Pepper. Why History Simplicity Operating Systems – Function Call Stack.
09-1 Queues and List-Based ADT Implementations Problem Set: PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 09 Monday, February 26 Handout #18.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
1 Iterators "First things first, but not necessarily in that order " -Dr. Who CS Computer Science II.
Information and Computer Sciences University of Hawaii, Manoa
Using Iterators Trey Chandler Burlington Williams High School Mr. Langner’s Class,
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
Iterators ITI 1121 N. El Kadri. Motivation Given a (singly) linked-list implementation of the interface List, defined as follows, public interface List.
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Iterator Pattern. Traversing two different collections  When bringing two previously developed objects together, it can be difficult to change an implementation.
Iteration Abstraction SWE Software Construction Fall 2009.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
Iterator Summary Slides by Entesar Al-Mosallam adopted from Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
CS Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /29/2016 Changes of Office Hours  Monday.
CS 46B: Introduction to Data Structures July 21 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Recursive Objects Singly Linked List (Part 2) 1. Operations at the head of the list  operations at the head of the list require special handling because.
Chapter 5 – Part 3 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/19 Outline The if Statement and Conditions Other Conditional.
Functional Processing of Collections (Advanced) 6.0.
1 Iterator Pattern (A Behavioral Pattern) Prepared by: Neha Tomar.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Iterators. Iterator  An iterator is any object that allows one to step through each element in a list (or, more generally, some collection).
1 Iterators & the Collection Classes. 2 » The Collection Framework classes provided in the JAVA API(Application Programmer Interface) contains many type.
IndexedListWithIteratorsViaLinear1Ind
Linked Data Structures
Sets Set is an unordered list of items
Week 4 - Friday CS221.
Week 3 - Friday CS221.
Chapter 5 Structures.
Introduction to Collections
Introduction to Collections
CS 1110 Final Exam: Review Session 1 Drawing frames for calls, executing method calls Biggest issue!!! You can’t do questions on this topic correctly.
"First things first, but not necessarily in that order " -Dr. Who
null, true, and false are also reserved.
Introduction to Collections
CSE 143 Lecture 27: Advanced List Implementation
Iterator.
"First things first, but not necessarily in that order." -Dr. Who
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSE 214 – Computer Science I More on Linked Lists
LabVIEW.
CS 1110 Final Exam: Review Session 1 Drawing frames for calls, executing method calls Biggest issue!!! You can’t do questions on this topic correctly.
Introduction to Collections
Interator and Iterable
"First things first, but not necessarily in that order " -Dr. Who
Introduction to Collections
JCF Collection classes and interfaces
"First things first, but not necessarily in that order " -Dr. Who
TCSS 143, Autumn 2004 Lecture Notes
Presentation transcript:

CS 280 Data Structures Professor John Peterson

Project 9 Questions? IS280

Exam #2 Next Wednesday. All period. I’ll answer review questions Monday. This will cover links and recursion.

The Final Link Topic An Iterator is a class that returns values from a collection or some other sequence one at a time. This uses a bunch of built-in Java classes and special syntax. Iterator for loops: for (x : value) {body} This extracts items one by one from the collection x and executes the body

The Syntax for (x : v) { body} is the same as temp = v.iterator(); while (temp.hasNext()) { x = temp.next(); body}

Iterable Interface These are built in: public interface Iterable { Iterator iterator(); } public interface Iterator { boolean hasNext(); \\Returns true if the iteration has more elements. E next(); \\ Returns the next element in the iteration. void remove(); \\ Removes from the underlying collection the last element returned by the iterator (optional operation). }

Example: A Link Iterator public class ListIterator implements Iterator { public Link here; public ListIterator(Link here) { this.here = here; } public boolean hasNext() { return here != null; } public T next() { T res = here.data; here = here.link; return res; } public void remove() { System.out.print("Error: can't remove lists!"); }

Link public class Link implements Iterable { … public Iterator iterator() { return new ListIterator(this); }

Example: Printing public static String printList(Link x) { if (x == null) return "{}"; // Why? boolean first = true; String res = ""; for (T v : x) { res = res + (first ? "{" : ", "); res = res + v.toString(); first = false; } return res + "}"; }