- Home /
Printing an ordered list
I have been working on this program for a WHILE now and I got it working for the most part. What my program does is randomly picks an element from a list of strings. I have been told by @HappyMoo (who has been a BIG help so far) to create another list to store the order in which the strings are selected. But what I need help with is how to print out what order according to the random string generator.
This diagram should help:
I also tried using extension classes to output the random strings but all that does is just print the list together and not separately how I want it.
Also, what @ArkaneX said also made it clear to me what I had to do which was use ToArray() to output the list. The problem is that it only outputs the list in the default order.
string[] gestureOptions = {
Cube_DemoPhase.task1Gesture[0],
Cube_DemoPhase.task1Gesture[1],
Cube_DemoPhase.task1Gesture[2]
};
Next, I managed to create the following but this does not work as it only outputs the list in the default order as well.
for (int i = gestureOptions.Length - 1; i > 0; i--)
{
gestureOptions[i] = Cube_DemoPhase.index[i].ToString();
}
What I wanted to do here is output the string list based in the order that the random number generator has chosen.
Can anyone help me figure out what I need to do to get to work how I want it? Thank you again!
Can you show the code of your random number generator? It seems that you can just make a list and consecutively add randomly generated items to it, so the order will persist through this process
I have. I have an extra list that stores the random int, what I need to know is how do I get it to work in the for loop I created
As an example of over-complication, why do you initialize an array to the values of another array individually like that? It is a very hard-coded solution that assumes the length of the source array never changes. Better to use System.Array.Copy ins$$anonymous$$d so that you can safely change the source's length without worry.
Answer by Mikea15 · Jan 10, 2014 at 02:11 PM
You can use .net's SortedList Collection.
More info after the jump => http://www.dotnetperls.com/sortedlist
Just add them and set the ordering to be the Random Number generator. You will probably have to check if you can add the same ordering number twice tho. And I don't know if this is supported by Mono.
Cheers.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Making a camera list 1 Answer
my random task generator not working 1 Answer
Printing a GUI selection grid in order 1 Answer
Multiple Cars not working 1 Answer