Download
preorder traversal with a stack n.
Skip this Video
Loading SlideShow in 5 Seconds..
Preorder Traversal with a Stack PowerPoint Presentation
Download Presentation
Preorder Traversal with a Stack

Preorder Traversal with a Stack

210 Views Download Presentation
Download Presentation

Preorder Traversal with a Stack

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