How to Reverse a Linked List in groups of given size
In this video, we are going to look at one of the famous interview questions on linked list: reversing a linkedlist in groups. Description: Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list. If the number of nodes is not a multiple of k then leftout nodes, in the end, should be considered as a group and must be reversed. Input:LinkedList: 12345 K 3Output: 3 2 1 5 4 Link: Each element in a linked list consists of two parts: Data: This part stores the data value of the node. That is the information to be stored at the current node. Next Pointer: This is the pointer variable or any other variable which stores the addr. .., ProgrammingKnowledge, DataStructuresAndAlgorithms, DataStructures, algorithm, Algorithms, AlgorithmsTutorial, DataStructuresTutorial, Arrays, Strings, Stacks 20220707 h1A6ZGknhDw
|
|