CSE 109 Test 1 FALL 2003

CSE 109 Test 1 FALL 2003 - CSE 109 Test 1 Wednesday 1...

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

View Full Document Right Arrow Icon
CSE 109 Test 1 Wednesday 1 October 2003 >>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<,, 1. Assume that your function height(Node *rt) from programming assignment #1 works properly, returning -1 when rt==NULL and returning the height of the tree of which rt is the root node otherwise. Write the declaration and definition of a member function, balanced(), which returns true if and only if the tree is balanced. You may also want to define some other member function(s) that balance() calls. A tree is balanced if for every node the difference between the heights of the two children is -1, 0, or 1. Code using this function would look like: Tree a; .... .... if(a.balanced()). .... ------------------------------ bool balanced(); bool balanced(Node *rt); bool Tree::balanced() {return balanced(root);} bool Tree::balanced(Node *rt) {int diff; if(rt==NULL) return true; diff=height(rt->child[Node::LEFT])-height(r->child[Node::RIGHT]); & balanced(rt->child[Node::RIGHT]); } ------------------------------ 2. Write a program whose only purpose is to display "good" when all the files (if any) specified on the command line begin with an uppercase letter and to display "bad" otherwise. If the name of the compiled program is "silly", then
Background image of page 1

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

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

Page1 / 3

CSE 109 Test 1 FALL 2003 - CSE 109 Test 1 Wednesday 1...

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

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