Write a method named flatten
that accepts a reference to a Grid
of integers as a parameter and that returns a Vector
with the contents of the original grid "flattened" into a one-dimensional vector.
For example, if the given grid is declared:
Grid<int> matrix {
{ 3, 8, 12},
{ 2, 9, 17},
{ 43, -8, 46},
{203, 14, 97}
};
Then the call of flatten(matrix)
should return the following vector:
{3, 8, 12, 2, 9, 17, 43, -8, 46, 203, 14, 97}
Your code should work for a grid of any size, even one with 0 rows or columns.
Your method should not modify the grid that is passed in.