Created
November 15, 2009 01:47
-
-
Save kellypleahy/234915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var rootList = new List<Node>(new[]{ new Node() }); // only ever one root, I assume. | |
var childrenAtThisLevel = FillLevel(rootList); | |
while(childrenAtThisLevel.Count > 0) | |
childrenAtThisLevel = FillLevel(childrenAtThisLevel); | |
} | |
List<Node> FillLevel(List<Node> childrenAtThisLevel) | |
{ | |
var childrenAtNextLevel = new List<Node>(); | |
foreach(var child in childrenAtThisLevel) | |
{ | |
child.Label = GetNextSymbol(); | |
var newChildCount = GetNumberOfChildrenForThisSymbolType(child.Label) // 0 1 or 2 | |
for(var i=0; i<newChildCount; i++) | |
{ | |
var newChild = new Node(); | |
child.Children.Add(newNode); | |
childrenAtNextLevel.Add(newChild); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment