Re: Traversing an array spirally
On Feb 2, 6:51 pm, Praveen <rpraveen1...@gmail.com> wrote:
> Hi,
>
> I would like to know how to traverse an array spirally?
> i.e if I have an array as follows
>
> 1 2 3 4
> 5 6 7 8
> 9 10 11 12
>
> I want the output to be 1 2 3 4 8 12 11 10 9 5 6 7.
>
> Please
Hmm I guess this is not s C question, but anyway this is my strategy
strategy 1
1. print first line
2. remove first line
3. take transpose of matrix
4 go to step 1 till matrix is not empty
strategy 2
assuming a function printcircle(mat) that prints boundary circle of a
matrix beginning at first element
i=0,j=0
1. printcircle(&(mat[i][j]))
2. i++,j++
3. goto step 1 till matrix is not empty
|