The answers you gave actually works, but is there any actual difference between one aproch and another?(vector of vectors vs. vector+arithmetic index).
Yep, there are differences.
- An array of arrays is not the same as a "2D array". They are different concepts.
- With an array of arrays, every row can be a different size, which means keeping them in-sync can be a nuisance, depending on what you're doing.
- Using math means you can treat the array as 1D when it benefits you, and 2D when it benefits you. Best of both worlds.
One example of this is iterating over every element - you can iterate over it as 1D when it doesn't matter what order you are accessing them in. - A vector of vectors keeps every vector in a different location of memory, so it can't be cached as effectively. If the code is at very low level, this might be important. If it's high-level, it doesn't matter much.
Learning new ways to do something helps to exercise your mind.