Question: Uplc NOT File Mai Q5 [16M]. The function Interchange () takes the address of the first node of a singly linked list and interchange the
Uplc NOT File Mai Q5 [16M]. The function Interchange () takes the address of the first node of a singly linked list and interchange the first and the last node. For example, if the linked list is: 1->2> 3 -> 4 -> 5, the function modifies the list to be 5 -> 2 -> 3 -> 4 -> 1. Complete the following implementation of the function, strictly as instructed in the comments. Worst case time complexity of the function is O(N), performs the required task in single traversal of the list, and work by only modifying the pointers. This means, you are not allowed to modify the data field of any node, create new nodes, use any data structure for temporary storage (like arrays, queues, etc.), and so on. Write the complete code as your answer (along with required comments). typedef struct node NODE* InterChange (NODE *first) { 1 int data; NODE *temp1, 'temp2; struct node *next; //Do not declare any new pointer variable(s). NODE; //Write code below considering the list has either zero or one node. temp1 = first; // Write code below to point templ to second last node. //Using temp2 as an additional variable, write code below to perform //the required task of interchanging. //Finally, check if the above code also works for 2-element list. // Write "YES IT WORK" if it works; "NO, IT WONT WORK" if it doesn't // If your answer is NO, write code below to make it work. return first
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
