title: Find all possible routes, from root to leaf, on a tree that has multiple children per node.
body: <p>I'm currently working on a project which requires me to find multiple routes, from a given station on the london underground. The project i'm having is the creation of routes. I have created a method with uses DFS and recursion. 
  This method takes in the name of the starting station, an empty List and an integer value. When I execute the method using the following code:</p>
  
  <pre><code>GetRoutes("HOLBORN", list, 4);
  </code></pre>
  
  <p>I get the following results in my list </p>
  
  <pre><code>HOLBORN
  CHANCERY LANE
  ST PAULS
  BANK
  LIVERPOOL STREET
  TOTTENHAM COURT ROAD
  OXFORD CIRCUS
  RUSSELL SQUARE
  KINGS CROSS
  COVENT GARDEN
  </code></pre>
  
  <p>The first strings in the list display a valid path:</p>
  
  <pre><code>HOLBORN =&gt; CHANCERY LANE =&gt; ST PAULS =&gt; BANK =&gt; LIVERPOOL STREET
  </code></pre>
  
  <p>However, I then need it to search again for alternate routes like:</p>
  
  <pre><code>HOLBORN =&gt; CHANCERY LANE =&gt; ST PAULS =&gt; BANK =&gt; LONDON BRIDGE
  </code></pre>
  
  <p>Here is questionable method:</p>
  
  <pre><code>    public List&lt;string&gt; GetRoutes(string stationName, List&lt;string&gt; completeRoutes, int counter)
      {
          Stack&lt;Node&lt;TrainData&gt;&gt; s = new Stack&lt;Node&lt;TrainData&gt;&gt;();
  
          s.Push(GetRootStationNode(stationName));
  
          while (s.Count &gt; 0)
          {
              var currentNode = s.Pop();
              if(!VisitedStation(currentNode.State.StationName, completeRoutes))
              {
                  completeRoutes.Add(currentNode.State.StationName);
              }
  
              var allPossibleStation = GetAllPossibleNextStations(currentNode.State.StationName);
  
              foreach (var node in allPossibleStation)
              {
                  if (counter &gt; 0)
                  {
                      if (!node.Visited)
                      {
                          node.Visited = true;
                          s.Push(node);
                          counter--;
                          GetRoutes(node.State.StationName, completeRoutes, counter);
                      }
                  }
              }
          }
  
          return completeRoutes;
      }
  </code></pre>
  
  <p>Here is the GetAllPossibleNextStations that retrieves all the child nodes of a particular station:</p>
  
  <pre><code>  public List&lt;Node&lt;TrainData&gt;&gt; GetAllPossibleNextStations(string input)
      {
          var possibleStations = new List&lt;TrainData&gt;();
          var NodeList = new List&lt;Node&lt;TrainData&gt;&gt;();
  
          var stationsMatchingInput = from f in dbList
                                      where f.StationName == input
                                      select f;
  
          foreach (var station in stationsMatchingInput)
          {
              var node = GetNextStation(station.PositionId);
              if (node != null &amp;&amp; (node.State.Line == station.Line))
              {
                  NodeList.Add(node);
              }
          }
  </code></pre>
  
  <p>I can't seem to get my head around this traversal business, so any suggestions would be great.</p>