Page 1 of 1

Given a linked list, write a C program to reverse every K nodes (where K is an input to the function). Example : Sample

Posted: Mon Mar 21, 2022 4:49 pm
by answerhappygod
Given A Linked List Write A C Program To Reverse Every K Nodes Where K Is An Input To The Function Example Sample 1
Given A Linked List Write A C Program To Reverse Every K Nodes Where K Is An Input To The Function Example Sample 1 (77.94 KiB) Viewed 66 times
linked list
Given a linked list, write a C program to reverse every K nodes (where K is an input to the function). Example : Sample Test Cases Test Case 1: Input: 1+2+3+4+5NULL and K = 2 Output: 2+14+3+5NULL Test Case 2: Input: 1->2->3->4->5->6->7->8->NULL, K = 3 Output: 3->2->1->6->5->4->8->7->NULL Test Case 3: Input: 1->2->3->4->5->6->7->8->NULL, K = 5 Output: 5->4->3->2->1->8->7->6->NULL Do the following: 1. Write the steps for the recursive function reverse(head, K), where head is the pointer to first node in the linked list and K is the desired input as mentioned in the problem. 2. Illustrate the recursive calls through diagrams of the function reverse for the Test Case 1. 3. Write the C program (handwritten on paper) on your system to implement the operations creation, display (traverse) and reverse. Validate your program with the given three test cases and attach the screenshots for output obtained after execution.