Iterative Tree traversal : Breadthfirst - PowerPoint PPT Presentation

1 / 1
About This Presentation
Title:

Iterative Tree traversal : Breadthfirst

Description:

traverse the list by level by level and visit each node. template class T ... store siblings of each node in a queue so that they are ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 2
Provided by: eceg6
Category:

less

Transcript and Presenter's Notes

Title: Iterative Tree traversal : Breadthfirst


1
Iterative Tree traversal Breadth-first
  • // traverse the list by level by level and visit
    each node
  • template ltclass Tgt
  • void LevelScan(TreeNodeltTgt t, void visit(T
    item))
  • // store siblings of each node in a queue so
    that they are
  • // visited in order at the next level of the
    tree
  • QueueltTreeNodeltTgt gt Q
  • TreeNodeltTgt p
  • // initialize the queue by inserting the root
    in the queue
  • Q.QInsert(t)
  • // continue the iterative process until the
    queue is empty
  • while(!Q.QEmpty())
  • // delete front node from queue and execute
    visit function
  • p Q.QDelete()
  • coutltltp-gtdata()//do what you will do when you
    visit the node
Write a Comment
User Comments (0)
About PowerShow.com