The following recursive function inserts a value as the last item in a linked im
ID: 3901634 • Letter: T
Question
The following recursive function inserts a value as the last item in a linked implementation of a list. Read the following code and determine what goes in blank #4.
void Insert(NodeType*& listNode, ValueType value)
// Pre: listNode is defined.
// listNode is a pointer to a list.
// Post:value is inserted in a node, which is placed at the end of the list
{
if (listNode == ________) // 1
{
listNode = _______ NodeType; // 2
____________ = value; // 3
____________ = NULL; // 4
}
else Insert(___________, value); // 5
}
[1] listNode->next
[2] listNode->info
[3] value
Explanation / Answer
Answer: Option 1 i.e. listNode -> next = NULL
As a new node is being added, the "next" pointer needs to be initialized to NULL at the line #4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.