TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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;
}
Reply
Answers (
0
)
regex
Check id and password using web services c#