Quiz 6 Grading Criteria, Page 4 of 5
[p4] 15 points
Identify and correct any errors in the following code. You may assume that the comments are complete and
correct. Remember that the type declarations for this module are at the beginning of the quiz.
procedure Add_Card (new_card isoftype in Baseball_Card,
my_collection isoftype in ptr toa Collection)
//Adds a card to the collection in the correct place.
//Precondition: my_collection is a BST sorted on the homerun field.
//Postcondition: my collection has the new card inserted in the appropriate
// location.
if (my_collection = NIL) then
temp^.data <- new_card
temp^.left <- NIL
temp^.right <- NIL
my_collection <- temp
elseif (new_card^.homerun > my_collection^.data.homerun) then
Add_Card (new_card, my_collection^.right)
else
Add_Card (new_card, my_collection^.left)
endif
endprocedure // Add_Card
LINES=8
[c4] 15 points
Error corrections (other possible ways to repair):
[p5] 15 points
Given the following BST, what is the output that is printed for the following code segment.
12
/ \
/ \
/ \
9 27
/ \ / \
8 10 24 34
/ / / \
7 14 28 41
/ \
4 18
\ \
6 21