Confidential Teaching Materials
Homework 5 Criteria, Page 1 of 11
Homework 5 Grading Criteria
Note: To receive any credit whatsoever, 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] 15 points
Each of the following code segments contain a single error. Identify the error, explain why it is an error, and
write a corrected code segment. The following error-free linked list definition applies to all three segments:
List_Node definesa record
data isoftype Num
next isoftype ptr toa List_Node
endrecord
a) procedure Add_To_Front (head isoftype in/out ptr toa List_Node,
data_to_add isoftype in Num)
temp isoftype ptr toa List_Node
temp <- new (List_Node)
temp^.data <- data_to_add
temp^.next <- head^.next
head <- temp
endprocedure
(b) procedure Delete_Last_Node (head isoftype in/out ptr toa List_Node)
if (head^.next = NIL) then
head <- NIL
else
Delete_Last_Node (head^.next)
endif
endprocedure
(c) procedure Add_to_End (head isoftype in/out ptr toa List_Node,
data_to_add isoftype in Num)
if (head = NIL) then
head^.data <- data_to_add
head^.next <- NIL
else
Add_To_End (head^.next, data_to_add)
endif
endprocedure
[c1] 15 points