# CSI2110 Lab5- Binary Tree Traversals and Iterators Solved

30.00 \$ 15.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

Rate this product

### Binary tree traversals

During lectures, we have discussed binary tree traversals. Your first task is to implement recursive methods to do preorder, inorder and postorder traversals. This should be a simple task, based on pseudocodes seen in lecture, and take only a few minutes to code and test. More specifically complete the following methods inside LikedBinarySearchTree class:

• void preorderRecursive(Node)
• void inorderRecursive(Node)
• void postorderRecursive(Node)
• Binary tree iterators In a previous course, you probably have studied the concept of an iterator for a class; you might have studied in more detail list iterators.

### In this lab you will apply the concept of an iterator for a binary tree. While a list iterator is a way to move through elements of a list from beginning to end, for a tree there are many ways to move from node to node. For this part you will implement two types of iterators: a preorder and an order iterator.

You may need to review information about the Interface Iterator&ltE&gt provided in package java.util. Your TA will briefly review iterators during the lab. Your iterators will implement this interface, so you need to provide the the constructor plus methods hasNext() and next() for each iterator implemented.

The hardest method to implement for class InorderIterator implements Iterator is next() as it entails to figure out from the current node of your iterator, who is the next node to be visited in an inorder traversal of the tree. The same is true for class PreorderIterator implements Iterator.

The pseudocode of the algorithms to do these tasks have been discussed in your DGD and will also be reviewed by your TA in the lab.