From the course: C# Hands-on Practice with Data-Structures

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

GitHub Codespaces Solution: Train station platform management

GitHub Codespaces Solution: Train station platform management - C# Tutorial

From the course: C# Hands-on Practice with Data-Structures

GitHub Codespaces Solution: Train station platform management

Let's use data structures to manage trains and tracks for a train platform system. When a train arrives, it should be added to a queue for holding until it's assigned to a track. As more trains arrive, they'll be added to this queue and assigned a track in first-in, first-out order. Let's create our queue. This will hold the trains waiting to be assigned a track. Our platform will have several tracks, so let's manage those with a list. We'll add a few to get us started. To retrieve all the trains and tracks, we can return these data structure references. The next train to be assigned a track will be at the top of our queue. So as long as this queue is not empty, we can take a peek at the top element and return it. Otherwise, we'll return null. When a train arrives, we'll add it to our train queue so it's ready for track assignment. To assign the next train to a track, we'll first need to get the next train that needs assignment. We can use our GetNextTrain method for this. If this…

Contents