Question: Rearrange Nodes in C We are given a singly linked list. Let the length of the linked list be N. If the N is even
We are given a singly linked list. Let the length of the linked list be N. If the N is even number, we divide nodes in the linked list into two groups, the first N/2 nodes (L1-L2->L3...) and the next N/2 nodes (R1->R2->R3...). If the N is odd number, we divide the nodes into the first N/2 nodes and the next N/2+1 nodes. Next, we rearrange the nodes in the linked list as (R1->L1->R2->L2->R3->...). After that, we divide nodes in the rearranged linked list into two groups in the same manner. (L1'->L2'->L3'... and R1'->R2'->R3'...). Lastly, we rearrange the nodes again as (L1'->R1'->L2->R2->L3- >R3!...). If the N is odd number, the last node will remain at the last position. Write a function rearrange() which realise this rearrangement of a linked list. 2. 3 The function prototype is given as follow: LinkedList rearrange (LinkedList II); Input: A single line data ends with a non-digit symbol. Example: Input: 1 2 3 4 5 6 7 8 9 10 a Output: 6 319 7 4 2 10 8 5 a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
