Here is my solution in Java: (I already know that a Pointer points to an specific adress on memory or is declared to make that purpose on C, and because Java does not supports pointers I did this with a non C Pointer logic) So , that said, I did this with the logic of point to the "address" (rown, column) of the matrix.
static void MatrixTravelPointer(int [][] m){
int pointerX = 0;
int pointerY = 0;
List elements = new ArrayList<>();
int maxlength_ = 0;
int pos = 0;
for(int i=0;i 1 && turn == true && pointerX == turns - 1){
turn = false;
}
if(turn == false){
if(pointerY < m[0].length - turns){
pointerY++;
} else if(pointerX < m.length - turns){
pointerX++;
}
}
if(turn == true)
{
if(pointerY >= turns - 1){
pointerY--;
} else if(pointerX >= turns - 1){
pointerX--;
}
}
pos++;
}
System.out.print("\n");
Iterator it = elements.iterator();
while(it.hasNext()){
System.out.print(" "+(int)it.next());
}
}
For now my logic only works for cubic and rectangular matrix.
The logic goes like this using a 4x4 matrix:
Pointer travels in the matrix from [0][0] to [0][3] , at this point it turns the travel pointer to go from [0][3] to [3][3], imagine a top down "L" on Tetris ,at this point we can omit or erase the top row and right column and reverse the travel point from right to left using -- and from down to top. Because each time we form an "L" on the "second turn" we need to reduce the travel size (the "L" size) with the "turns" var depending on the times we form an "L".