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

The following code is present: #include <cstdlib> #include <iostream> using name

ID: 3694399 • Letter: T

Question

The following code is present:

#include <cstdlib>

#include <iostream>

using namespace std;

struct list_node

{

       char stuff;

       list_node* next;

};

typedef list_node* list_ptr;

void build (list_ptr& front, int nodes, char ch);

void print (list_ptr front);

int main(int argc, char *argv[])

{

    list_ptr front;

   

    build (front, 10, 'u');

    cout << " The list is: ";

    print (front);

   

    cout << " ";

    return 0;

}

void build (list_ptr& front, int nodes, char ch)

{

     if (nodes == 0)

        front = NULL;

     else

     {

         front = new list_node;

         front -> stuff = ch;

         build (front -> next, nodes - 1, ch + 1);

     }

}

void print (list_ptr front)

{

     if (front != NULL)

     {

        cout << front -> stuff << " ";

        print (front -> next);

     }

}

1. The function build creates a linked list pointed to by its first parameter. What would the value of front be set equal to if the following call was made?

build (front, 0, 'B');

2. In the recursive call in build, nodes–1 is passed as a second parameter. How does this expression help the function to eventually reach its base case?

3. How many nodes will be in the list created by the following call?

build (front, 4, 'C');

4. What is the base case for the print function?

5. The print function does not appear to have an action for the base case. Why does it not have an action?

Write a recursive function sub1_skip, (prototype and definition) that subtracts 1 from the stuff field of every other (starting with the first) node in a list. Takes a pointer to a list as its only parameter.

Write a recursive function make_Zs, (prototype and definition) that changes the stuff field for all non-lowercase letters to an uppercase Z. Takes a pointer to a list as its only parameter.

Call these two functions from main (before the cout << “ ”;) and call print to display the final list with a label (“ The final list is: “).

CPP File---------------------------

Explanation / Answer

1. The function build creates a linked list pointed to by its first parameter. What would the value offront be set equal to if the following call was made?

build (front, 0, 'B');

built function takes the second parameter as the number of nodes. Here you specified it as 0. Therefore, no nodes will be created, and front will point to NULL.

2. In the recursive call in build, nodes–1 is passed as a second parameter. How does this expression help the function to eventually reach its base case?

As, I specified in the previous session, the second parameter is the number of nodes, and the base case is, if the second parameter is 0, front will now point to NULL. Therefore, whatever positive value is passed to the function initially, the value will be decreased by 1 for every call, and therefore will eventually reach the base case.

3. How many nodes will be in the list created by the following call?

build (front, 4, 'C');

The 2nd parameter specifies the number of nodes. And therefore, 4 nodes will be created. And the nodes will be:

C D E F.

4. What is the base case for the print function?

The base case for print function is front == NULL. This is where the recursion will come to end.

5. The print function does not appear to have an action for the base case. Why does it not have an action?

The print function is just printing the value in the node, and moving to the next node. And the base case is when pointing to null node. Therefore, if the base case is satisfied, that means if there are no nodes, obviously you don't have things to display.

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