1 / 11

CS 112 - Fall 2012 , Lab 04

CS 112 - Fall 2012 , Lab 04. Haohan Zhu. Changes of Office Hours. Monday. 5-6:30 p.m. Tuesday . 5-6:30 p.m . Wednesday. 3-4:30 p.m. Arrays. An array is a container object that holds a fixed number of values of a single type.

Download Presentation

CS 112 - Fall 2012 , Lab 04

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. CS 112 - Fall 2012, Lab 04 Haohan Zhu

  2. CS 112 - Fall 2012, Lab 04 Changes of Office Hours • Monday. 5-6:30 p.m. • Tuesday. 5-6:30 p.m. • Wednesday. 3-4:30 p.m.

  3. CS 112 - Fall 2012, Lab 04 Arrays • An array is a container object that holds a fixed number of values of a single type. • The length of an array is established when the array is created. After creation, its length is fixed.

  4. CS 112 - Fall 2012, Lab 04 Data Structure from the lectures • Bags Not in Java API • Can contain duplicate elements • Queues Interface in Java API as Queue • FIFO • Stacks Class in Java API as Stack • LIFO Implementation of List • Linked lists Class in Java API as LinkedList • Implementation of List

  5. CS 112 - Fall 2012, Lab 04 Java Collection • Collection Interface & Class (as Collections) • Set (not Bag) Interface • Cannot contain duplicate elements • Queue Interface • FIFO • List Interface & Class (as List) • Can contain duplicate elements, ordered

  6. CS 112 - Fall 2012, Lab 04 Implementation of Set • Set • http://docs.oracle.com/javase/7/docs/api/java/util/Set.html • HashSet<E> • http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html

  7. CS 112 - Fall 2012, Lab 04 Implementation of Queue • Queue • http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html • PriorityQueue<E> • http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html

  8. CS 112 - Fall 2012, Lab 04 Implementation of List • List • http://docs.oracle.com/javase/7/docs/api/java/util/List.html • ArrayList • LinkedList • Stack • Vector

  9. CS 112 - Fall 2012, Lab 04 Iterator • Iterator is an interface • http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html • Methods of Iterator • hasNext() • next() • remove()

  10. CS 112 - Fall 2012, Lab 04 Practice • Pruning duplicate elements from a collection that has duplicate elements 7 4 4 3 5 2 3 7 7 4 4 3 5 2 3 7

  11. CS 112 - Fall 2012, Lab 04 Practice • Use Hashset to prune • Use iterator(), addAll in Hashset • Assume we have 1 million elements in an ArrayList or Queue, and we do not know how many elements have duplicates. We should use another Hashset to help us prune all duplicates in our ArrayList or Queue. Use Iterator to traverse the Hashset.

More Related