CS 106B Lecture Notes - Lecture 6: Foreach Loop

26 views2 pages

Document Summary

Assignment 2 goes out today; assignment 2 due next saturday: for our good (or not) Answer to this question will use adts (abstract data types: recap: vectors. Can grow to any size you need. Problem #1: count number of unique words in moby dick: there is no contains function for vector, but can write another function to replace it . Sets: collection of elements with no duplicates. Add, contains, remove operations are all fast. Also has size, isempty, and other functions. Use for-each loop with sets; can"t use for loops. Can use operators to compare two sets. Hashset: element order is jumbled in hashset vs. iterated over elements in sorted order in a set, even faster than set. Hashmap: element order is jumbled, faster than map. Examples of map: can use map to count how many times a certain word/ character/ object appears, e. g. counting votes, tally words.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers