Originally Posted by
laserlight
Why are you modifying the matrix? You're tracing a path, so you should store pointers to the entries in another container such that they are linked to form the path, e.g., in a linked list. By modifying the matrix itself, you have effectively "destroyed" it, i.e., it is no longer a matrix.
I suggest that you do this with a 2D array (as in vector of vectors) as the matrix representation, since you are not actually dealing with a sparse matrix. This will help you to use a linked list to store pointers to the matrix entries while resisting the urge to change the next pointers of the linked lists in the matrix representation, which perhaps would be easier for you to envision. Later, you can rework this for your original vector of linked lists representation.