Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 112 - Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 2 2/29/2016 Changes of Office Hours  Monday.

Similar presentations


Presentation on theme: "CS 112 - Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 2 2/29/2016 Changes of Office Hours  Monday."— Presentation transcript:

1 CS 112 - Fall 2012, Lab 04 Haohan Zhu

2 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 2 2/29/2016 Changes of Office Hours  Monday. 5-6:30 p.m.  Tuesday. 5-6:30 p.m.  Wednesday. 3-4:30 p.m.

3 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 3 2/29/2016 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 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 4 2/29/2016 Data Structure from the lectures  BagsNot in Java API  Can contain duplicate elements  QueuesInterface in Java API as Queue  FIFO  StacksClass in Java API as Stack  LIFOImplementation of List  Linked listsClass in Java API as LinkedList  Implementation of List

5 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 5 2/29/2016 Java Collection  CollectionInterface & Class (as Collections)  Set (not Bag)Interface  Cannot contain duplicate elements  QueueInterface  FIFO  ListInterface & Class (as List)  Can contain duplicate elements, ordered

6 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 6 2/29/2016 Implementation of Set  Set  http://docs.oracle.com/javase/7/docs/api/java/util/Set.html http://docs.oracle.com/javase/7/docs/api/java/util/Set.html  HashSet  http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html

7 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 7 2/29/2016 Implementation of Queue  Queue  http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html  PriorityQueue  http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.htm l http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.htm l

8 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 8 2/29/2016 Implementation of List  List  http://docs.oracle.com/javase/7/docs/api/java/util/List.html http://docs.oracle.com/javase/7/docs/api/java/util/List.html  ArrayList  LinkedList  Stack  Vector

9 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 9 2/29/2016 Iterator  Iterator is an interface  http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html  Methods of Iterator  hasNext()  next()  remove()

10 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 10 2/29/2016 Practice  Pruning duplicate elements from a collection that has duplicate elements 74435237 74435237

11 Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 11 2/29/2016 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.


Download ppt "CS 112 - Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 04 2 2/29/2016 Changes of Office Hours  Monday."

Similar presentations


Ads by Google