Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Thanked 0 Times in 0 Posts

    Exclamation Two Dementional Array Spiral Fill

    How could i write two methods... one recursive and one not to fill a two dementional array of size n.

    ex. 5 x 5 array

    0 1 2 3 4
    15 16 17 18 5
    14 23 24 19 6
    12 22 21 20 7
    12 11 10 9 8

    the non-recursive routine would be like void spiralFill(int [][]a, int n) where it spiral fills the first n rows and columns

  2. #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Thanked 20 Times in 19 Posts
    There are a couple of ways to do this, but we wont do it for you! What have you come up with for ideas thus far?

    For the non-recursive way, think about how you would go adding to each element in the array. It may help to do the non-recursive part first, then move onto the recursive part (assuming you're a newer student, this would be easier).

    Think about how he array's are filled, and how you could possibly loop that.

    Let us know what you come up with.
    "To iterate is human, to recurse divine." -L. Peter Deutsch


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts