1 / 16

Collection types for specific functionalities

Choose the appropriate collection type for different scenarios such as finding the largest number, accessing elements using an index, spell checking, retrieving values in a specific order, looking up definitions, counting letter frequencies, finding word occurrences, managing printer jobs, and evaluating arithmetic expressions.

sruiz
Télécharger la présentation

Collection types for specific functionalities

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. Exercise 1.a. Page 246 You want a collection that always returns the largest number. Which would you choose: • Queue • Priority Queue • Stack • List

  2. Exercise 1.b. Page 246 You want a collection that provides access to an element using an index. • Queue • Set • List • Map

  3. Exercise 1.c. Page 246 You want to input a word from a file and determine if it is in a collection of correctly spelled words. • LinkedList • TreeSet • TreeMap • ArrayList

  4. Exercise 1.d. Page 246 The next value out is the last value that was put in. • Queue • Stack • List • Set

  5. Exercise 1.e. Page 246 To get a value ¾ of the way through the collection, move through the proceeding values. • Stack • LinkedList • HashSet • ArrayList

  6. Exercise 1.f. Page 246 The first value put in is the next value out. • Queue • Map • Priority Queue • Stack

  7. Exercise 1.g. Page 246 Input a word, look it up in a collection, and output the definition of the word. • Queue • Set • Map • List

  8. Another problem You want to count the frequency of the letters in a text passage and print them out in alphabetic order. • HashSet or TreeSet • Stack • Queue • Priority Queue • List • HashMap • TreeMap

  9. Another problem You want to count the frequency of the letters in a text passage and print them out from most frequent to least frequent. • HashSet or TreeSet • Stack • Queue • Priority Queue • List • HashMap • TreeMap

  10. Another problem You want to find all line numbers where a word appears in a text passage and print them out in order. • HashSet or TreeSet • Stack • Queue • Priority Queue • List • HashMap • TreeMap

  11. Another problem A structure to hold jobs at a printer that will be handled on a first come, first served basis. • HashSet or TreeSet • Stack • Queue • Priority Queue • List • HashMap • TreeMap

  12. Another problem You want to evaluate an arithmetic expression containing +, -, *, / in correct algebraic order (this is, 2+3*4 = 14) • HashSet or TreeSet • Stack • Queue • Priority Queue • List • HashMap • TreeMap

  13. Implementing Set Operations • Use a bag to return the union of two sets passed in as parameters • Make your method generic

  14. Implementing Set Operations • Use a bag to return the intersection of two sets passed in as parameters • Make your method generic

  15. Implementing Set Operations • Use a bag to return the set difference of two sets passed in as parameters • Make your method generic

  16. Implementing Set Operations • Write a test program to see if union, intersection, and set difference work properly

More Related