Matthew Smith

Matthew Smith

  • NA
  • 2
  • 2.1k

recursive function not generating expected output

Dec 3 2015 9:47 AM
I have a loop that calls a recursive function repeatedly to increment an array.  The purpose of this is to build an array, incrementing the lowest element by one, and carrying over to the next element once it reaches 96.  The expected output should be something like this:
 
[1]
[2]
...
[95]
[1][0]
[1][1]
..
[1][95]
[2][0]
 
etc.
 
When I run the program, it just keeps looping over the first element from 1 to 95 over and over.  I cannot spot why it is doing this.  Any help would be appreciated.
 
 
public static int[] IncrementValue(int[] TheInputList, int ThePosition)
        {
            //Increment the character value
            TheInputList[ThePosition]++;
            if (TheInputList[ThePosition] == 96)
            {
                TheInputList[ThePosition] = 0;
                int CheckingArrayLength = ThePosition + 2;
                if (TheInputList.Length < CheckingArrayLength)
                {
                    Array.Resize(ref TheInputList, CheckingArrayLength);
                }
                TheInputList = IncrementValue(TheInputList, ThePosition + 1);
            }
            return TheInputList;

        }