What is the purpose of the 0-or-1 neighbor element?
Same idea as a linked list. Only this can potentially branch.
Why do you keep track of the enumerator manually?
Is there some method of keeping track of it automatically?
What kind of traversal are you trying to perform?
Move to the first child first, then to any of it's children/neighbors next ect, return to the parent when you reach the end, repeat for the next child until there are no more children, move to the neighbor.
public class FileParseElement
{
string token;
FileParseElement Neighbor;
List<FileParseElement> Children;
List<FileParseElement>.Enumerator CurrentChild;
public static FileParseElement BuildFullObjectStructure(ref List<string>.Enumerator ittr){...}
public static FileParseElement BuildObjectSet(ref List<string>.Enumerator ittr){...}
public string Token
{
get { return token; }
}
public FPE_Iterator GetIterator()
{
return new FPE_Iterator(this) { };
}
public class FPE_Iterator //this IS a nested class
{
FileParseElement Head;
Stack<FileParseElement> ParrentStack;
public FPE_Iterator(FileParseElement FPE)
{
ParrentStack = new Stack<FileParseElement>();
Head = FPE;
}
public FileParseElement Current
{
get { return Head; }
}
public bool Movenext()
{
if (Head.Children != null)
{
if (Head.CurrentChild != new List<FileParseElement>.Enumerator()) //compiler doesn't allow this
{
ParrentStack.Push(Head);
Head = Head.Children.GetEnumerator().Current;
return true;
}
}
if (Head.Neighbor != null /*&& I have no children or finished tracversing them*/)
{
Head = Head.Neighbor;
return true;
}
else
{
//pop a parent off the stack and assign it to Head
return false;
}
}
}
}
Movenext() is what I'm working on now. It's far from compleet