Have a Question ?

Home / Answered Questions / Other / ncorrect-question-25-include-using-namespace-std-struct-listnode-string-data-listnode-next-int-main--aw453

(Solved): Ncorrect Question 25 #include Using Namespace Std; Struct ListNode { String Data; ListNode *next; In...


ncorrect Question 25 #include <iostream> using namespace std; struct ListNode { string data; ListNode *next; int main() { Lis

ncorrect Question 25 #include <iostream> using namespace std; struct ListNode { string data; ListNode *next; int main() { ListNode *ptr, *list; list = new ListNode; list->data = "Boston"; ptr = new ListNode; ptr->data - "New York"; ptr->next = nullptry list->next = new ListNode; list->next->data = "Houston"; list->next->next = ptr; // new code goes here Which of the following code correctly deletes the node with value "Boston" from the it list->next = list: delete list: list = list->next; delete ptr: por list: list = list->next delete pt None of these ptr = list->next; list->next - ptr: delete ptr:


We have an Answer from Expert View Expert Answer

Expert Answer


Solution: Last option will suffer from the dangling pointer problem as the list-> next contains the value present in ptr and in the last line this ptr is dele
We have an Answer from Expert
Buy This Answer $5

-- OR --

Subscribe To View Unlimited Answers
Subscribe $12 / Month