-
Initialize Result Vector:
- Create a
result
vector to store the coordinates of the matrix in spiral order.
- Create a
-
Define Directions:
- Define four possible movement directions: right, down, left, and up.
-
Initialize Steps and Direction:
- Start with 1 step and initialize the direction index to 0 (right).
-
Set Starting Position:
- Set the starting position to the given
rStart
andcStart
. - Add the starting position to the
result
.
- Set the starting position to the given
-
Loop Until All Cells Are Visited:
- Continue the loop until the
result
contains all the coordinates of the matrix. - For each direction, move
steps
times and then change the direction. - If the new position is within the bounds of the matrix, add it to the
result
.
- Continue the loop until the
-
Increase Steps:
- After moving in two directions, increase the number of steps.
-
Return Result:
- Return the
result
containing the coordinates of the matrix in spiral order.
- Return the
-
Initialize Result List:
- Create a
result
list to store the coordinates of the matrix in spiral order.
- Create a
-
Define Directions:
- Define four possible movement directions: right, down, left, and up.
-
Initialize Steps and Direction:
- Start with 1 step and initialize the direction index to 0 (right).
-
Set Starting Position:
- Set the starting position to the given
rStart
andcStart
. - Add the starting position to the
result
.
- Set the starting position to the given
-
Loop Until All Cells Are Visited:
- Continue the loop until the
result
contains all the coordinates of the matrix. - For each direction, move
steps
times and then change the direction. - If the new position is within the bounds of the matrix, add it to the
result
.
- Continue the loop until the
-
Increase Steps:
- After moving in two directions, increase the number of steps.
-
Convert Result to Array:
- Convert the
result
list to an array and return it.
- Convert the
-
Initialize Result Array:
- Create a
result
array to store the coordinates of the matrix in spiral order.
- Create a
-
Define Directions:
- Define four possible movement directions: right, down, left, and up.
-
Initialize Steps and Direction:
- Start with 1 step and initialize the direction index to 0 (right).
-
Set Starting Position:
- Set the starting position to the given
rStart
andcStart
. - Add the starting position to the
result
.
- Set the starting position to the given
-
Loop Until All Cells Are Visited:
- Continue the loop until the
result
contains all the coordinates of the matrix. - For each direction, move
steps
times and then change the direction. - If the new position is within the bounds of the matrix, add it to the
result
.
- Continue the loop until the
-
Increase Steps:
- After moving in two directions, increase the number of steps.
-
Return Result:
- Return the
result
containing the coordinates of the matrix in spiral order.
- Return the
-
Initialize Result List:
- Create a
result
list to store the coordinates of the matrix in spiral order.
- Create a
-
Define Directions:
- Define four possible movement directions: right, down, left, and up.
-
Initialize Steps and Direction:
- Start with 1 step and initialize the direction index to 0 (right).
-
Set Starting Position:
- Set the starting position to the given
rStart
andcStart
. - Add the starting position to the
result
.
- Set the starting position to the given
-
Loop Until All Cells Are Visited:
- Continue the loop until the
result
contains all the coordinates of the matrix. - For each direction, move
steps
times and then change the direction. - If the new position is within the bounds of the matrix, add it to the
result
.
- Continue the loop until the
-
Increase Steps:
- After moving in two directions, increase the number of steps.
-
Return Result:
- Return the
result
containing the coordinates of the matrix in spiral order.
- Return the
-
Initialize Result Slice:
- Create a
result
slice to store the coordinates of the matrix in spiral order.
- Create a
-
Define Directions:
- Define four possible movement directions: right, down, left, and up.
-
Initialize Steps and Direction:
- Start with 1 step and initialize the direction index to 0 (right).
-
Set Starting Position:
- Set the starting position to the given
rStart
andcStart
. - Add the starting position to the
result
.
- Set the starting position to the given
-
Loop Until All Cells Are Visited:
- Continue the loop until the
result
contains all the coordinates of the matrix. - For each direction, move
steps
times and then change the direction. - If the new position is within the bounds of the matrix, add it to the
result
.
- Continue the loop until the
-
Increase Steps:
- After moving in two directions, increase the number of steps.
-
Return Result:
- Return the
result
containing the coordinates of the matrix in spiral order.
- Return the