1 votes 1 votes Consider the following linked list : Which of the following piece of code will insert the node pointed to by $q$ at the end of the list ? $\text{for (p=list; p !=NULL; p=p → next);}\\ p=q;$ $\text{for (p=list; p !=NULL; p=p → next);}\\ \text{p→next=q;}$ $\text{for (p=list; p→next !=NULL; p=p → next);}\\ p=q;$ $\text{for (p=list; p→next !=NULL; p=p → next);}\\ p→next=q;$ DS ugcnetcse-dec2007-paper2 + – go_editor asked Mar 28, 2020 • edited Jun 11, 2020 by soujanyareddy13 go_editor 852 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply vg653 commented Mar 28, 2020 reply Follow Share Answer should be D. 1 votes 1 votes arunsinghsaab commented Jun 17, 2020 reply Follow Share Option D 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes To insert a node at last following procedure must be followed: 1. The list is traversed up to the last node. 2. Link field of the last node is updated (now pointing to the new node) So option (D) is correct. Here link field is updated only one time. Harsh Sonwani answered Mar 29, 2020 Harsh Sonwani comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes // Reach the last node and stop. for (p=list; p→next !=NULL; p=p → next); // Change the next pointer of the last node to point to the NEW NODE. p→next=q; AkashChandraGupta answered Aug 6, 2020 AkashChandraGupta comment Share Follow See all 0 reply Please log in or register to add a comment.