1 / 13

Preorder Traversal with a Stack

Preorder Traversal with a Stack. Push the root onto the stack. While the stack is not empty pop the stack and visit it push its two children. 14. 14 84 13 53 06 99 72 43 33 64 97 51 25. Stack. 14. 43. 84. 16. 33. 97. 13. 72. 53. 99. 64. Preorder Traversal with a Stack.

shanae
Download Presentation

Preorder Traversal with a Stack

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 14 14 84 13 53 06 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 64

  2. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 84 43 14 84 13 53 06 99 72 43 33 64 97 51 25 Stack 14 14 43 84 16 33 97 13 72 53 99 64

  3. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 13 16 43 14 84 13 53 06 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 64

  4. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 53 16 43 14 84 13 53 06 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 13 72 53 99 64

  5. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 16 43 14 84 13 53 06 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 53 64

  6. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 99 72 43 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 6 33 97 13 72 53 99 64

  7. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 72 43 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 99 64

  8. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 43 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 72 53 99 64

  9. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 33 97 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 43 84 16 33 97 13 72 53 99 64

  10. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 64 97 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 33 97 13 72 53 99 64

  11. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 97 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 64 64

  12. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 97 13 72 53 99 64

  13. Preorder Traversal with a Stack • Push the root onto the stack. • While the stack is not empty • pop the stack and visit it • push its two children 14 84 13 53 16 99 72 43 33 64 97 51 25 Stack 14 43 84 16 33 97 13 72 53 99 64

More Related