collections, part two€¦ · tokenscanner the tokenscanner class can be used to break apart a...
TRANSCRIPT
![Page 1: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/1.jpg)
Collections, Part Two
![Page 2: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/2.jpg)
Today
● Short Review From Last Week● Vector
● Grid
● Vector Performance
● Containers: Common mistakes
![Page 3: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/3.jpg)
From Last Week...
![Page 4: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/4.jpg)
A recursive solution is a solution that is defined in terms of itself.
![Page 5: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/5.jpg)
Recursion: Fibonacci Numbers
● Fibonacci Numbers● 0, 1, 1, 2, 3, 5, 8, 13, 21, …● Defined recursively:
fib(n) = n if n = 0 or 1fib(n-1) + fib(n-2) otherwise
![Page 6: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/6.jpg)
Another View of Factorials
n! = 1 if n = 0n × (n – 1)! otherwise
int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); }}
![Page 7: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/7.jpg)
TokenScanner
● The TokenScanner class can be used to break apart a string into smaller pieces.
● Construct a TokenScanner to piece apart a string as follows:
TokenScanner scanner(str);
● Configure options (ignore comments, ignore spaces, add operators, etc.)
● Use the following loop to read tokens one at a time:
while (scanner.hasMoreTokens()) {
string token = scanner.nextToken();
/* … process token … */
}
● Check the documentation for more details; there are some really cool tricks you can do with the TokenScanner!
![Page 8: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/8.jpg)
Stack
● A Stack is a data structure representing a stack of things.
● Objects can be pushed on top of the stack or popped from the top of the stack.
● Only the top of the stack can be accessed; no other objects in the stack are visible.
● Example: Function calls
0
42
137
![Page 9: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/9.jpg)
Vector
![Page 10: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/10.jpg)
Vector
● The Vector is a collection class representing a list of things.● Similar to Java's ArrayList type.
● Probably the single most commonly used collection type in all programming.
![Page 11: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/11.jpg)
Example: Cell Tower Purchasing
![Page 12: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/12.jpg)
Buying Cell Towers
137 42 95 272 52
![Page 13: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/13.jpg)
Buying Cell Towers
137 42 95 272 52
![Page 14: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/14.jpg)
Buying Cell Towers
14 22 13 25 30 11 9
![Page 15: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/15.jpg)
Buying Cell Towers
14 22 13 25 30 11 9
![Page 16: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/16.jpg)
Buying Cell Towers
● Given the populations of each city, what is the largest number of people you can provide service to given that no two cell towers are adjacent?
● Proposed Algorithm: Iteratively pick the “largest population” cell towers from the set of remaining towers we can select● Problems with this algorithm?
![Page 17: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/17.jpg)
Proposed Algorithm: Problem
99 100 99
![Page 18: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/18.jpg)
Proposed Algorithm: Problem
99 100 99
![Page 19: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/19.jpg)
Buying Cell Towers
● Our proposed algorithm won't always give us the correct answer!
● Correct algorithm is best explained pictorially...
![Page 20: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/20.jpg)
14 22 13 25 30 11 9
![Page 21: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/21.jpg)
14 22 13 25 30 11 9
![Page 22: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/22.jpg)
14 22 13 25 30 11 9
![Page 23: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/23.jpg)
14 22 13 25 30 11 9
Maximize what's left in here.
![Page 24: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/24.jpg)
14 22 13 25 30 11 9
14 22 13 25 30 11 9
Maximize what's left in here.
![Page 25: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/25.jpg)
14 22 13 25 30 11 9
14 22 13 25 30 11 9
Maximize what's left in here.
![Page 26: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/26.jpg)
14 22 13 25 30 11 9
14 22 13 25 30 11 9
Maximize what's left in here.
Maximize what's left in here.
![Page 27: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/27.jpg)
Cell-towers Pseudocode(On Board)
![Page 28: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/28.jpg)
cell-towers.cpp(On Computer)
![Page 29: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/29.jpg)
14 22 13
How the Recursion Works
![Page 30: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/30.jpg)
14 22 13
22 13
How the Recursion Works
![Page 31: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/31.jpg)
14 22 13
22 13
13
How the Recursion Works
![Page 32: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/32.jpg)
14 22 13
22 13
13
How the Recursion Works
Best is13
![Page 33: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/33.jpg)
14 22 13
22 13
13
How the Recursion Works
+22
Best is13
![Page 34: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/34.jpg)
14 22 13
22 13
13
How the Recursion Works
+22
Best is13
Best is0
![Page 35: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/35.jpg)
14 22 13
22 13
13
How the Recursion Works
+22
Best is13
Best is0
Best is22
![Page 36: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/36.jpg)
14 22 13
22 13
13
13
How the Recursion Works
+14
+22
Best is13
Best is0
Best is22
![Page 37: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/37.jpg)
14 22 13
22 13
13
13
How the Recursion Works
+14
+22
Best is13
Best is0
Best is22
Best is13
![Page 38: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/38.jpg)
14 22 13
22 13
13
13
How the Recursion Works
+14
+22
Best is13
Best is0
Best is22
Best is13
Best is27
![Page 39: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/39.jpg)
How the Recursion Works
20 25 23 17
25 23 17
23 17
17
17
23 17
17
Best:17
Best:0
Best:0
Best:17
Best:17
+25 +23
+20
Best:23
Best:32
Best:23
Best:43
+23
![Page 40: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/40.jpg)
Pass-by-Reference and Objects
● Recall: In C++, all parameters are passed by value unless specified otherwise.
● Passing by value makes a copy of the parameter
● When using container types (Stack, Vector, etc.) it is often useful to use pass-by-reference for efficiency reasons.
● Takes a long time to make a copy of a large collection!
● Let's see what happens when we do this for cell-towers.cpp!
![Page 41: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/41.jpg)
Vector or Stack?
● Any Stack can be replaced with a Vector with which we only add and remove from the back.● So why should we ever use a Stack?● Hint: It's not for performance reasons
![Page 42: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/42.jpg)
Vector or Stack?
● Reason 1: It makes your code easier to read
● Someone reading your code knows that you are only going to read and add to the top of the Stack.
● Reason 2: It protects you from making mistakes
● If you use a Vector, you might accidentally add/read/remove from the middle instead of the end.
● Summary: Use Stack when the algorithm lets you, otherwise use Vector
![Page 43: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/43.jpg)
Grid
![Page 44: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/44.jpg)
Two-Dimensional Data
● The Grid type can be used to store two-dimensional data.● e.g. matrices, scrabble boards, etc.
● Can construct a grid of a certain size by writing
Grid<Type> g(numRows, numCols);
● Can access individual elements by writing
g[rows][cols]
![Page 45: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/45.jpg)
Stanford is not as safe as it seems...
![Page 46: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/46.jpg)
Velociraptors Spotted on Campus!
● Everyone knows how dangerous velociraptors are, but not everyone knows how to survive an attack.
![Page 47: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/47.jpg)
Good News
● Luckily, velociraptors are constrained to exist on cells of a Grid!
![Page 48: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/48.jpg)
Good News
● Also, velociraptors can only move in the 8 cardinal and ordinal directions
![Page 49: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/49.jpg)
Good News
● A natural question arises – given a grid of locations of velociraptors, is there a position on the grid that is safe?
![Page 50: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/50.jpg)
Good News
● A natural question arises – given a grid of locations of velociraptors, is there a position on the grid that is safe?
● Represent the grid with...a Grid<bool> where true indicates that a velociraptor is there.
![Page 51: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/51.jpg)
Good News
● A natural question arises – given a grid of locations of velociraptors, is there a position on the grid that is safe?
● Represent the grid with...a Grid<bool> where true indicates that a velociraptor is there.
F F F F F F F F
F F F F F F T F
F F F T F F F F
F F F F F F F F
F F F F F F F T
F T F F F F F F
F F F F T F F F
F F F F F F F F
![Page 52: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/52.jpg)
raptor-defense.cpp(Computer)
![Page 53: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/53.jpg)
Grid or Vector<Vector >?
● Any Grid can be replaced with a Vector<Vector > in which we make the length of the “inner vectors” equal● So why should we ever use a Grid?
● For reasons similar to the “Vector or Stack” decision:● Easier to read.● Less likely to make a mistake.
![Page 54: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/54.jpg)
Vector Performance● Where you add/remove from a Vector
can have a huge performance impact
![Page 55: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/55.jpg)
Vector Performance?
Vector<int> myVector;
for (int i = 0; i < 1000; i++)
myVector[i] = 0;
Vector<int> myVector;
for (int i = 0; i < 1000; i++)
myVector.insert(0,i);
vs
![Page 56: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/56.jpg)
Vector Performance● Why was this?
● When you remove (or insert) at the beginning of a Vector, all the other elements in the Vector must be shifted over
● This can have big performance consequences– We will learn about other data structures that
solve this
● It turns out, reading from a Vector takes the same amount of time no matter where you read from● We'll learn why later in the quarter
![Page 57: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/57.jpg)
Collections: Common Pitfall 1
Vector numbers;
![Page 58: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/58.jpg)
Collections: Common Pitfall 1
Vector<int> numbers;
![Page 59: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/59.jpg)
Collections: Common Pitfall 2
Vector<Vector<int>> numbers;
![Page 60: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/60.jpg)
Collections: Common Pitfall 2
Vector<Vector<int> > numbers;
![Page 61: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/61.jpg)
Collections: Common Pitfall 3
void myFunction(Grid<bool> bigGrid);
![Page 62: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/62.jpg)
Collections: Common Pitfall 3
void myFunction(Grid<bool> &bigGrid);
![Page 63: Collections, Part Two€¦ · TokenScanner The TokenScanner class can be used to break apart a string into smaller pieces. Construct a TokenScanner to piece apart a string as follows:](https://reader036.vdocument.in/reader036/viewer/2022071003/5fbff6b055298973987ee552/html5/thumbnails/63.jpg)
Next Time
● Map● A collection for storing associations between
elements.● Set
● A collection for storing an unordered group of elements.
● Lexicon● A special kind of Set.