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

C++ Programming 1. Suppose that first is a pointer to a linked list. What is sto

ID: 3730796 • Letter: C

Question

C++ Programming

1. Suppose that first is a pointer to a linked list. What is stored in first?

2. Consider the linked list shown in the figure below. Assume that the nodes are in the usual info-link form. Use this list to answer Exercises 6 through 14. If necessary, declare additional variables. (Assume that list, current, temp, trail, and last are pointers of type nodeType.)

What are the effects, if any, of each of the following C++ statements?

a. trail->link = NULL;
   delete last;

b. temp->link =trail;

c. list->info = 19;

d. current = current->link;
    current->link = temp->link;

3. Using the figure from question 2 what is the output of the following C++ code?

a. while (current != NULL)
    cout << current->info << " ";
    current = current->link;
    cout << endl;

b. while (current != last)
    current = current->link;
    cout << current->info << " ";
    cout << endl;

4. Using the figure from question 2:

a. If the following C++ code is valid, show the output. If it is invalid, explain why.

      ccurrent = temp->link;
      trail = list;
      temp = list->link;
      trail = temp;
      temp->link = current->link;
      current = trail->link;
      cout << trail->info << " " << current->info << endl;

5. Assume that the node of a linked list is in the usual info-link form with the info of type int. (list and ptr are pointers of type     nodeType.) The following code creates a linked list:

   ptr = new nodeType;
   ptr->info = 16;
   list = new nodeType;
   list->info = 25;
   list->link = ptr;
   ptr = new nodeType;
   ptr->info = 12;
   ptr->link = NULL;
   list->link->link = ptr;

Use the linked list created by this code to answer the following questions. (These questions are independent of each other.) Declare additional poin- ters if you need them.

a. Which pointer points to the first node of the linked list?

b. Determine the order of the nodes of the linked list.

c. Write a C++ code that creates and inserts a node with info 45 after the node with info 16.

d. Write a C++ code that creates and inserts a node with info 58 before the node with info 25. Does this require you to the change the value of the pointer that was pointing to the first node of the linked list?

e. Write a C++ code that deletes the node with info 25. Does this require you to the change the value of the pointer that was pointing to the first node of the linked list?

Explanation / Answer

As per chegg policy, I am answering first 4 subparts only.

1.) First will contain the address of the first element of the linked list.

2.) a.) It will delete last node of the which is containing 39. Now, the last node is 65.

b.) Pointer of node containing 86 will point to node pointing by trail i.e., node containing 65 because of that link to node containing 10 is lost.

c.) Change the value of first node from 75 to 19.

d.) First current will point to node having info 35. And then node having info 35 will point to node having info 10.

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