Traversing a 2D Matrix in C++
Introduction
Hello, fellow coder! Are you excited to dive into a new, intriguing coding challenge? In this lesson, we're going to explore special traversals of matrices. Using the C++ programming language, we'll find our way through a matrix by climbing up and down the columns, zigzagging as we go. Sound exciting? Buckle up, then, and get ready!
Task Statement
Solution Building: Step 1
The first step towards a solution is understanding the dimensions of the matrix with which we're working. We can do this using C++'s member functions such as size(). Let's set up our function and identify the matrix size:
Solution Building: Step 2
Now that we're aware of the matrix dimensions, we should establish the starting point (bottom-right) and the direction of travel (upward initially). Additionally, we'll need a vector to keep track of the cells we've visited in order:
