Iterative Inorder Traversal Instructor Prof JyhShing Roger Jang

  • Slides: 9
Download presentation
Iterative Inorder Traversal Instructor : Prof. Jyh-Shing Roger Jang Designer:Shao-Huan Wang The ideas are

Iterative Inorder Traversal Instructor : Prof. Jyh-Shing Roger Jang Designer:Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “.

Iterative Inorder Traversal 1. First, we prepare a array stack and a binary tree

Iterative Inorder Traversal 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL A C B D E F H D B G I J K L A NULL

Iterative Inorder Traversal 1. First, we prepare a array stack and a binary tree

Iterative Inorder Traversal 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 D C B D E F H D H B G I J K L A NULL

Iterative Inorder Traversal DHB D 1. First, we prepare a array stack and a

Iterative Inorder Traversal DHB D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G H H B E I J K L A NULL

Iterative Inorder Traversal D HBEA D 1. First, we prepare a array stack and

Iterative Inorder Traversal D HBEA D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G H E F I J K L A C NULL

Iterative Inorder Traversal D H B EAF C D 1. First, we prepare a

Iterative Inorder Traversal D H B EAF C D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G H IF I J K L C G NULL

Iterative Inorder Traversal D H B EAF CJ I D 1. First, we prepare

Iterative Inorder Traversal D H B EAF CJ I D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G H J I K I J K L G NULL

Iterative Inorder Traversal D H B EAF CJ I KL D 1. First, we

Iterative Inorder Traversal D H B EAF CJ I KL D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G H K L I J K L G NULL

Iterative Inorder Traversal D H B E A F C J I K LG

Iterative Inorder Traversal D H B E A F C J I K LG D 1. First, we prepare a array stack and a binary tree 2. Push the node to stack and find left child until NULL 3. If the node is NULL, pop term from stack 4. Print the node and find right child A and go to step 2 5. If right child is NULL, C B pop term from stack and go to step 4 E F G 6. If right child is NULL and stack is empty, H I stop the traversal J K L G NULL