Skip to main content

Section 14.5 Single Dimension Traversals

It is also possible to traverse just one dimension of a multidimensional set of data. Say we just want to print out the third row of a table of data. This only requires traversing in one dimension - side to side through a single row. The list of elements we need to visit looks like:
matrix.at(2).at(0)
matrix.at(2).at(1)
matrix.at(2).at(2)
matrix.at(2).at(3)
Figure 14.5.1. The third row of data in a 3x4 matrix.
The row of everything we are trying to access is 2. The column number is the only one that changes. This means we can use a set value for the row index. We still have to specify both a row and column to access a single int value in the table. We just will use a fixed value for the row.
Listing 14.5.2.
You have attempted of activities on this page.