[Data Structure] Program Design of Print Snake Matrix

xiaoxiao2021-03-06  105

I saw a friend on the Internet to ask the snake matrix problem, and I wrote one, and I also talk about the design method here.

The design of the serpentine matrix is ​​not difficult, the key to the design is looking for a route. The a snake matrix is ​​as follows:

1 2 9 10 25

4 3 8 11 24

5 6 7 12 23

16 15 14 13 22

17 18 19 20 21 We look into two routes and two jumpers in the direction of the snake pattern, and the number 1 does not look, the route 1 is from top to the left, such as 2-3-4 and 10-11 -12-13-14-15-16, route 2 is from left to right, such as 5-6-7-8-9 and 17-18-9-20 -...- 25. The jumper is a two route path. It is characterized, and the jumper 1 is "jumping" of the line 2 to the line 1, and features are columns. The jumper 2 is a "jumping" of the line 1 to the line 2, and features are plug-in.

From the above analysis, we can get the role of the snake matrix to start from a [0] [0], jump to the line 1, jump to the line 2, and then jump to the line 1 ... We can set K as a main The number of elements on the corner is used to limit the row mark I, J is not off. And the jumper setting, we can find it is related to K.

The attachment procedures are as follows:

/ ** Copyright (C) 2004, Anhui University 02 Automation Professional * All Rights Reserved. * * File Name: Snakematrix.c * File ID: None * Summary: Print Snake Matrix * * Current Version: 1.0 * Author: YU * Completion Date: August 16, 2004 ** Replacement Version: 1.0 * Original Author: YU * Completion Date: August 16, 2004 * / # include

转载请注明原文地址:https://www.9cbs.com/read-126841.html

New Post(0)