{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw7 - ECE264 Spring 2008 Homework 7 Due Thu pm In a ternary...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE264 Spring 2008 Homework 7 Due Thu, Mar 20, 11pm In a ternary tree, each node has at most three children, referred to as the left, middle and right child of the node. The sorting rules for a sorted ternary tree are as follows: All the elements in the left subtree of a node are smaller than the element in the node. All the elements in the right subtree of a node are larger than the element in the node. All the elements in the middle subtree of a node are equal to the element in the node. Inorder traversal of the tree is defined recursively as follows: traverse the left subtree, the root, the middle subtree, and the right subtree. Write a program that reads a list of non-negative integers ending with a -1 and stores them in a sorted ternary tree. A new element should always be connected to a leaf. Print the tree inorder after every element is inserted. For example, for the input: 3 10 5 5 2 17 12 8 1 3 5 -1 The program should build the following tree: The program should print: 3 3 10 3 5 10 3 5 5 10 2 3 5 5 10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}