Sunday, August 14, 2011

Declaring an unknown amount of variables in C#?

I have an ignment to use the MergeSort algorithm which divides an array into 2 equal arrays, and which continues this process until each array has one variable. Then the arrays are combined, two at a time and sorted each time they are merged until only 1 sorted array exist. My problem is that user input will decide how many numbers are to be sorted and I'm not sure how to declare an uncertain amount of arrays and give each of them an individual name so that I can use them. To further explain, if I knew I was using 4 numbers, I could simply hardcode 7 array variables (1 to hold 4 numbers, 2 to hold 2, and 4 to hold 1) but without knowing how many arrays there are, I can't hardcode names into the program. I hope I explained that well enough for someone to understand. Any ideas? I'm using C#.

No comments:

Post a Comment