C SC 205 Lecture 16: Tree Maps and Tree Sets
major resources: Data Structures and the Java Collections Framework Second Edition, William Collins, McGraw-Hill, 2005
Introduction to Programming and OO Design using Java, Niño and Hosch, Wiley & Sons, 2002

[ previous | schedule | next ]

Wednesday November 7 (week 9)

The Map concept and java.util.Map interface

The Map<K,V> specification

The AbstractMap<K,V> class

The SortedMap<K,V> subinterface

The TreeMap<K,V> class

Using a TreeMap to sort an existing list

Beware: the list can contain duplicate values but the map cannot contain duplicate keys!
Handle this by associating a "count" value with each key -- the number of times it appears in list

  1. Iterate through list and for each element:
  2. Clear the list
  3. Get an entrySet() (collection view) for the map
  4. Iterate through the entry set and for each entry:

Think about the running time of this sort! What is it?

Set, SortedSet, AbstractSet, TreeSet


[ C SC 205 | Peter Sanderson | Math Sciences server  | Math Sciences home page | Otterbein ]

Last updated:
Peter Sanderson (PSanderson@otterbein.edu)