Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote