C++, your help will be great.Thanks in advance! exercise 1 What are the effects,
ID: 664770 • Letter: C
Question
C++, your help will be great.Thanks in advance!
exercise 1
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;
What is the output of the following C++ code?
e. while (current != NULL)
cout << current->info << " ";
current = current->link;
cout << endl;
f. while (current != last)
current = current->link;
cout << current->info << " ";
cout << endl;
Explanation / Answer
a. trail->link = NULL;
delete last;
Currently trail point to next node that is last node . Last is not null so condition is false .It won't be delete last node
b. temp->link = trail;
As per statement Temp node point too trail but as per screen shot temp node link to another node .
Temp node (86) ----> Node(10)
C. list->info = 19;
As per given linked list list valiue is not 19
D. current = current->link;
current->link = temp->link;
Current = 35
temp->link = 10
Current is point to next node and Next node is 35
Temp point to the next node that is 10 so here Current link is 10 so that is not valid
e.while (current != NULL)
cout << current->info << " ";
current = current->link;
cout << endl;
Output - > 75
Reason- As per while condition checking Current node is not null ..condition is true.then go to loop and print current node value that is 75
F. while (current != last)
current = current->link;
cout << current->info << " ";
cout << endl;
Output = 35
Reason -> As per while loop checking condition that Current node is not equal to last ..condition is true.then go to loop and print current node pointer.Current node point to next node that's value is 35
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.