CS 368 (C++): Lecture 8
Operator Overloading, const and Templates
Nov 9th, 2016
Lecture 9: Topics
How can we store data as a grid?
a00 | a01 | a02 |
a10 | a11 | a12 |
A vector of vectors!
std::vector<std::vector<int>> grid;
A vector of vectors!
std::vector<std::vector<int>> grid;
g00 | g01 | g02 |
g10 | g11 | g12 |
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid.resize(2);
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid.resize(2);
|
|
grid[0]
grid[1]
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid[0].resize(3);
|
|
grid[0]
grid[1]
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid[0].resize(3);
0 |
|
grid[0]
grid[1]
0 |
0 |
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid[1].resize(3);
0 |
|
grid[0]
grid[1]
0 |
0 |
How to initialize the vector of vectors?
std::vector<std::vector<int>> grid;
grid[1].resize(3);
0 |
0 |
grid[0]
grid[1]
0 |
0 |
0 |
0 |
How to access elements in a vector of vectors?
grid[0][0] = 3;
0 |
0 |
grid[0]
grid[1]
0 |
0 |
0 |
0 |
How to access elements in a vector of vectors?
grid[0][0] = 3;
0 |
0 |
grid[0]
grid[1]
0 |
0 |
0 |
0 |
How to access elements in a vector of vectors?
grid[0][0] = 3;
0 |
0 |
grid[0]
grid[1]
0 |
0 |
0 |
0 |
How to access elements in a vector of vectors?
grid[0][0] = 3;
3 |
0 |
grid[0]
grid[1]
0 |
0 |
0 |
0 |