0

Say I Have rail objects named 1 to 6, and trains objects that are passing throw them. Each rail can have one train.

I Have Two Tracks for the trains (Are a sequence of rails) and the tracks can include same rails.

For example:

Track1 : Rail1 - Rail2 - Rail3 - Rail4

Track2 : Rail4 - Rail3 - Rail5 - Rail6

I'm thinking about making collection for each track, now the problem is how can i know to which Rail the train should continue with. If the train is now at Rail3 (in example), how can it know if it should continue with Rail4 or Rail5. I have a RailManagerClass And The Tracks Should Be stored at that class. what is the best way for storing ang managing the tracks? will a linkedList solve the problem?

Thank you.

Community
  • 1
  • 1
  • Keep some sought of array of rails and a counter for each track, then when the train is ready to travel to the next rail just update the counter and index the array for that rail. – matthewr Dec 27 '12 at 06:24

1 Answers1

0

This looks like a homework :) in any case, if you are using c# then a linked list will solve your problem. Create two lists in your raulmanager class, add the tracks to them and then iterate over these lists to see where the train should go next.

corrego
  • 327
  • 1
  • 7
  • Yes sort of homework :) I tried using linkedlist, but i cant find any next object propertie in the linkedlist – David Gehtman Dec 27 '12 at 06:19
  • Well, there isn't any, because they are not needed. What you can do is to use a regular list, and then iterate up to Count-1 and peek the next element by saying i+1, where i is your counter. I don't want to solve your assignment but that should give you a starting point :) good luck – corrego Dec 27 '12 at 06:25