matrix.spiral_print =================== .. py:module:: matrix.spiral_print .. autoapi-nested-parse:: This program print the matrix in spiral form. This problem has been solved through recursive way. Matrix must satisfy below conditions i) matrix should be only one or two dimensional ii) number of column of all rows should be equal Attributes ---------- .. autoapisummary:: matrix.spiral_print.a Functions --------- .. autoapisummary:: matrix.spiral_print.check_matrix matrix.spiral_print.spiral_print_clockwise matrix.spiral_print.spiral_traversal Module Contents --------------- .. py:function:: check_matrix(matrix: list[list[int]]) -> bool .. py:function:: spiral_print_clockwise(a: list[list[int]]) -> None >>> spiral_print_clockwise([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) 1 2 3 4 8 12 11 10 9 5 6 7 .. py:function:: spiral_traversal(matrix: list[list]) -> list[int] >>> spiral_traversal([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] Example: matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] Algorithm: Step 1. first pop the 0 index list. (which is [1,2,3,4] and concatenate the output of [step 2]) Step 2. Now perform matrix's Transpose operation (Change rows to column and vice versa) and reverse the resultant matrix. Step 3. Pass the output of [2nd step], to same recursive function till base case hits. Dry Run: Stage 1. [1, 2, 3, 4] + spiral_traversal([ [8, 12], [7, 11], [6, 10], [5, 9]] ]) Stage 2. [1, 2, 3, 4, 8, 12] + spiral_traversal([ [11, 10, 9], [7, 6, 5] ]) Stage 3. [1, 2, 3, 4, 8, 12, 11, 10, 9] + spiral_traversal([ [5], [6], [7] ]) Stage 4. [1, 2, 3, 4, 8, 12, 11, 10, 9, 5] + spiral_traversal([ [5], [6], [7] ]) Stage 5. [1, 2, 3, 4, 8, 12, 11, 10, 9, 5] + spiral_traversal([[6, 7]]) Stage 6. [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] + spiral_traversal([]) .. py:data:: a :value: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]