Answer the question
In order to leave comments, you need to log in
How to print array elements clockwise?
How to display elements of an array clockwise? I understand that this is done recursively, but I do not know how to do it,
please tell me
Answer the question
In order to leave comments, you need to log in
Draw your array on a piece of paper and try to write the traversal logic. Obviously, at the extreme points, the conditions should be checked and the order of the elements output should be changed.
Once you learn, learn to think with your own head.
Understood nothing. What does "clockwise" mean? Two-dimensional array to bypass a spiral? Well, I don’t know where this can be applied, well then, yes, recursively is easier. We write a simple recursive function with a parameter - the depth of the descent - with a base of zero (or half the size of the array, so it will be clearer what the depth means). Then we go around the array exactly, take the first element, for example, the top right one. Then to the left. Have you reached the border? Now the bottom, so to the next border. Then we go to the right, and finally up. At the end, the function calls itself, descending further in depth.
If you need to print an array on the screen clockwise, then here you will need to select the center on the screen and move around the screen (for example, using VT100 codes or JCurses). A few sines - cosines. And magic - you can display the clock.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question