






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
W2(b) Lecture Notes (Skrentny) Material Type: Notes; Class: Introduction to Data Structures; Subject: COMPUTER SCIENCES; University: University of Wisconsin - Madison; Term: Spring 2014;
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Email [email protected] by this Friday if you:
Course Website - http://pages.cs.wisc.edu/~cs367-1/
Sign Up for Piazza
Homework 1 assigned tomorrow
Program 1 assigned tomorrow
Last Time
Today
Iterators
Next Time
What are they?
Concept
Operations
Suppose words is a SimpleArrayList
Write a code fragment that gets an iterator, named itr, from words.
Suppose words is a SimpleArrayList
Write a code fragment that uses itr to print each item in words.
Assume SimpleArrayList
Complete the method using iterators to determine list contains duplicates.
public boolean hasDups(SimpleArrayList
import java.util.*;
public class ArrayBagIterator
public ArrayBagIterator( ) {
}
public boolean hasNext() {
}
public E next() {
}
public void remove() {
}
}
import java.util.*;
public class ArrayBagIterator
public ArrayBagIterator( ) {
}
public boolean hasNext() {
}
public E next() {
}
public void remove() {
}
}
Concept
Coding ListADT using a generic Java interface
public interface ListADT
void add(E item);
void add(int pos, E item);
boolean contains(E item);
int size();
boolean isEmpty();
E get(int pos);
E remove(int pos);
}
Implementing ListADT using a generic array-based class
public class SimpleArrayList
private E[] items; // items in the List
private int numItems; // # of items in the List
public SimpleArrayList() { ... }
//*** required ListADT methods ***
public void add(E item) { ... }
public void add(int pos, E item) { ... }
public E remove(int pos) { ... }
public E get (int pos) { ... }
public boolean contains (E item) { ... }
public int size() { ... }
public boolean isEmpty() { ... }
//*** private methods ***
}