Quiz 5 Grading Criteria, Page 1 of 4
Confidential Teaching Materials:
Quiz 5 Grading Criteria
Note: To receive any credit whatsoever, the date, your name, your student number, and your answers must
be legible and readily readable in the judgment of the grader.
Add brief explanatory comments as necessary to make sure your answers are clear and unambiguous
to the grader.
[p1] 10 points
Find and correct any errors in the following module.
You may assume that all type declarations, headers, and comments are correct.
Tree_Node definesa record
data isoftype char
left_child isoftype ptr toa TreeNode
right_child isoftype ptr toa TreeNode
endrecord // Tree_Node
procedure BST_Insert (root isoftype in/out ptr toa TreeNode,
new_data isoftype in Char)
// Purpose: Adds the Char new_data to a binary search tree.
// Preconditions: root is initialized; if tree empty, it is nil.
// Postconditions: new_data is inserted into the tree such that BST
// ordering of nodes is maintained
if (root = NIL) then
root^.data <- new_data
root^.left_child <- NIL
root^.right_child <- NIL
else
if (new_data < root^.data) then
BST_Insert(root^.right_child, new_data)
else
BST_Insert(root^.left_child, new_data)
endif
endif
endprocedure // BST_Insert
LINES=12
[c1] 10 points
2 errors.
Should be:
root <– new(Tree_Node)