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

I have a final in c++ on wednseday and I need some help with the following revie

ID: 3583140 • Letter: I

Question

I have a final in c++ on wednseday and I need some help with the following review questions.

For questions 18-19 Correct the LOGIC ERROR present in each They both use the node class for linked list. next is a node pointer to the next element

18) //This code is supposed to count up the number of elements in a linked list, much like the assignment we did

// we have a node pointer to the head: node* head

node* currentNode= head;

int i=1;

while(currentNode—>next!=NULL) {

i=i+1;

currentNode=currentNode—>next;

What’s wrong with this code (hint— Think of some simple cases for our linked list)

19) //This code is supposed to remove the first element of the linked list

//we have a node pointer to the head node: node* head

if(head!=NULL)

head=head->next;

The above code will work but there’s something missing— update the code to make the program run better?

Explanation / Answer

18)

node* currentNode= head;

int i=1;

while(currentNode!=NULL)
{

i=i+1;

currentNode=currentNode—>next;
}

19)

if(head!=NULL)

head = head->next;