We have a square matrix (NxN) of integers. Having given a starting corner point and a direction, we want to walk all the elements from this matrix on a spiral way. I found this problem accidentally and it vexed me. That’s why I decided to create a simple algorithm.
We are going to create a class called SpiralWalk. It provides a method called WalkIt which does all the job. This methods has three arguments: starting row & col index (zero-based) and a direction. Remember, that the point must be a corner point. Every NxN array has four corner points: (0, 0), (0, N-1), (N-1, 0), (N-1, N-1). Continue Reading…