Implementing data structure with C #--Tree (ii)

Source: Internet
Author: User
Data structure and algorithm (C # Implementation) Series---tree (ii.)

Heavenkiller (original)

public class Inorder:iprepostvisitor

{

Private Ivisitor visitor;

Public inorder (Ivisitor _vis) {Visitor=_vis;}

#region Iprepostvisitor Members

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

}

#endregion

}

public class Postorder:iprepostvisitor

{

Private Ivisitor visitor;

Public Postorder (Ivisitor _vis) {Visitor=_vis;}

#region Iprepostvisitor Members

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);

}

#endregion

}

Protected class Enumvisitor:ivisitor

{

Queue Thisqueue;

Public Enumvisitor (Queue _que)

{

This.thisqueue=_que;

}

#region Ivisitor Members

public void Visit (object _obj)

{

TODO: Add enumvisitor.visit implementation

This.thisQueue.Enqueue (_obj);

}

#endregion

}

#region IEnumerable Members

Public IEnumerator GetEnumerator ()

{

TODO: Add Tree.getenumerator implementation

Enumvisitor vis=new Enumvisitor (this.keyqueue);

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 I!--void Settraversaltype (Traversaltype _type)");

throw new Exception ("Warning:please set a travel type first!"); /if not set a type, a exception would happen

Break

}

return This.keyqueue.GetEnumerator ();

}

#endregion



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.