0
hi help me
A program that receives an m*n matrix, then receives the starting point of the movement, i.e. the rows and columns are specified, and scrolls the matrix in a spiral manner.
3 Respuestas
+ 2
Please tag the relevant programming language and show what you have tried so far.
0
solution in python:
# Define a function to print out spiral matrix
def printSpiralMatrix(matrix, startRow, startCol):
rowSize = len(matrix) # Get the number of rows
colSize = len(matrix[0]) # Get the number of columns
# Set the global variables
global currRow
global currCol
currRow = startRow
currCol = startCol
# Define the directions
direction = 0
# Set the initial loop count
loopCount = 0
# Define the boundaries for the spiral
maxRow = rowSize - 1
minRow = 0
maxCol = colSize - 1
minCol = 0
# Loop until all elements are printed
while loopCount < rowSize * colSize:
# Set the counter to 1
loopCount += 1
# Print the element at the current row and column
print(matrix[currRow][currCol], end = " ")
# Move in the right direction
if direction == 0:
currCol)
0
currCol)
This part has an error