Level by level traversal of BST

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brij kishor
    New Member
    • Sep 2007
    • 2

    Level by level traversal of BST

    In java, how can we traverse a binary search tree level by level ?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Brij kishor
    In java, how can we traverse a binary search tree level by level ?
    You need a queue for that: first you push the root and you repeatedly pop a
    current node, process it and push its children to that queue again; all that
    until the queue is empty.

    You'd do it the same in C, C++, Java, SmallTalk or whatever.

    kind regards,

    Jos

    Comment

    Working...