Purpose

This assignment gives you experience implementing a level order traversal of a binary tree.

Pre-Assignment Prep

Study the Level Order Traversal Algorithm given in lecture 20 notes (slide 13) so that you understand the design of the method that you will need to implement in this lab.

Prior to the assignment, do the following to get started:

Download, save, and unzip the file binary_trees.zip on your removable media (floppy disk, Zip disk, or memory stick).

Assignment Activities

The LevelTraverse class has the main method. Its main method sets up a test case binary tree using the LinkedBinaryTree class and calls the LinkedBinaryTree class method LevelOrderIterator. It uses the iterator object obtained to print the contents of the tree in level order.

You need to design and add code to the levelOrderIterator method of the LinkedBinaryTree class where indicated.

1. Create a queue using the java.util.Queue interface and java.util.LinkedList class.

2. Create a linkedlist using the java.util.LinkedList class to contain the elements in level order.

3. Write code to implement the algorithm in the lecture notes (to be added!).

You need to complete your code for the levelOrderIterator method for use in Assignment 9.

A sample run of the finished program is shown here:

> java LevelTraverse

Root

Child1

Child2

Grandchild1

Grandchild2

. . .

Report (memo.txt)

In your report, explain why you got some nulls printed as part of the level order traversal.