Data Structure and Algorithm (C # Implementation) Series --- Tree (2)
HEAVENKILLER (original)
Public Class inorder: iprepostvisitor
{
Private Ivisitor Visitor;
Public inorder (ivisitor _vis) {visitor = _vis;}
#Region iprepostvisitor member
Public void previsit (Object _obj)
{
// Todo: Add inorder.previsit implementation
}
Public void visit (Object _obj)
{
// Todo: Add inorder.visit implementation
THIS.Visitor.visit (_OBJ);
}
Public void Postvisit (Object_Obj)
{
// Todo: Add inorder.postvisitor implementation
}
#ndregion
}
Public Class PostOrder: iprepostvisitor
{
Private Ivisitor Visitor;
Public postorder (ivisitor _vis) {visitor = _vis;}
#Region iprepostvisitor member
Public void previsit (Object _obj)
{
// Todo: Add PostOrder.Previsit implementation
}
Public void visit (Object _obj)
{
// Todo: Add PostOrder.visit implementation
}
Public void Postvisit (Object_Obj)
{
// Todo: Add PostOrder.postvisitor implementation
THIS.Visitor.visit (_OBJ);
}
#ndregion
}
Protected Class Enumvisitor: Ivisitor
{
Queue thisqueue;
Public Enumvisitor (Queue _QUE)
{
THIS.THISQUE = _QUE;
}
#Region Ivisitor member
Public void visit (Object _obj)
{
// Todo: Add enumvisitor.visit implementation
THIS.THISQUE.Enqueue (_OBJ);
}
#ndregion
}
#Region Ienumerable member
Public ienumerator geteNumerator ()
{
// Todo: Add Tree.GeteNumerator implementation
Enumvisitor VIS = New Enumvisitor (THISKEYQUE);
Switch (this.traversalType)
{
Case TraversalType.bReadth:
Breadthfirsttraversal (VIS);
Break;
Case traversaltype.predepth:
Preorder previs = new preorder (VIS);
DEPTHFIRSTTRAVERSAL (PREVIS);
Break;
Case TraversalType.indepth:
Inorder Invis = New Inorder (VIS);
DEPTHFIRSTTRAVERSAL (INVIS);
Break;
Case TraversalType.PostDepth:
PostORDER PostVis = New PostOrder (VIS);
DEPTHFIRSTTRAVERSAL (Postvis);
Break;
DEFAULT:
Console.writeline ("Warning: please set a travel type first! - void settraversaltype (traversaltype _type)"); // throw new exception ("Warning: please set a travel type first!"); // if not set a TYPE, A Exception Will Happen
Break;
}
Return this.keyQueue.Getenumerator ();
}
#ndregion