1 / 14

Week 7 Lectures

Week 7 Lectures. Set Abstract Data Type. Aims. Describe the Set Abstract Data Type Illustrate different implementations of the Set ADT Describe the Java Iterator concept. Learning Outcomes. specify the Set ADT write a Java program using one of the java.util set classes use an iterator

harvey
Télécharger la présentation

Week 7 Lectures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS2005 Week 7 Lectures Set Abstract Data Type

  2. CS2005 Aims • Describe the Set Abstract Data Type • Illustrate different implementations of the Set ADT • Describe the Java Iterator concept

  3. CS2005 Learning Outcomes • specify the Set ADT • write a Java program using one of the java.util set classes • use an iterator • recall the main points of Watt & Brown chapter 9.

  4. CS2005 The Set ADT • A set is a collection of elements, without any imposed order

  5. CS2005 Set Concepts • Null set (empty set) • Universal set • Disjoint sets • Subset • Equality

  6. CS2005 Set ADT • Essential Operations • create:  Set • add: Element  Set  Set • contains: Element  Set  Boolean • remove: Element  Set  Set • isEmpty: Set  Boolean

  7. CS2005 Set ADT (ii) • Other Operations • size: Set  Integer • equals: Set  Set  Boolean • copy: Set  Set • areDisjoint: Set  Set  Boolean • isSubset: Set  Set  Boolean • union: Set  Set  Set • intersection : Set  Set  Set • difference : Set  Set  Set

  8. CS2005 Set Implementations • Bitmap • e.g. to represent the set { ‘C’, ‘X’ } • see java.util.BitSet class

  9. CS2005 Set Implementations (ii) • Array • e.g. to represent the set { “baker”, “butcher”, “grocer” }

  10. CS2005 Set Implementations (iii) • Linked List • Binary Search Tree • Hash Table

  11. CS2005 Sets in Java Collection Classes • HashSet • TreeSet • addAll, retainAll, removeAll operations

  12. CS2005 Iterators • need for following concept for sets 1. for every member, m, of the set s 1.1 process m • Iterator used to solve this problem public interface Iterator { public abstract boolean hasNext(); public abstract Object next(); public abstract void remove(); }

  13. CS2005 Using an Iterator java.util.Iterator i; for (i = s.iterator(); i.hasNext(); ) { Object obj = i.next(); // the following code processes obj … }

  14. CS2005 Sample code • ArraySet • TestArraySet • HTML file

More Related