CmpE130Lab1 - CmpE130 Fall 2009 Lab 1 p. 1 CmpE130 Fall...

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

View Full Document Right Arrow Icon
CmpE130 Fall 2009 Lab 1 p. 1 CmpE130 Fall 2009 Lab Assignment 1 Binary Tree Due date : Thursday, 17 Sept. Last day to submit : 1 Oct. We will start with a review of some concepts already covered in CmpE126. We want to create a binary tree. Each node of the binary is defined like this: template <class Item> class binary_tree_node { public: place public member functions here private: Item data_field; binary_tree_node *left_ptr; binary_tree_node *right_ptr; }; 1 I use a template here to demonstrate good style, but in actual fact the data field is just going to be an integer in this first lab. To begin with, we just read a stream of positive integers from the standard input and build a binary tree. Of course we use the new operator to create new nodes for our binary tree as we need them. When we see an negative integer in the input, that is our sign to stop. Doing things in this way means a.) the first integer in the input will always be the root of the tree, and b.) there is no guarantee that the tree will be balanced. When the tree has been completely built, we will print it out using an in- order traversal, like this: 1 The code examples are taken from Michael Main & Walter Savitch, Data Structures and Other Objects Using C++ , 2001
Background image of page 1

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

View Full DocumentRight Arrow Icon
CmpE130 Fall 2009 Lab 1 p. 2 template <class Item> void inorder_print(const binary_tree_node<Item>* node_ptr)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

CmpE130Lab1 - CmpE130 Fall 2009 Lab 1 p. 1 CmpE130 Fall...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online