https://ide.codingblocks.com/s/330281 is not giving output pls check my code if possible make changes in it . but don’t change the whole code.pls tell my mistake…
Kreverse in linked list
https://ide.codingblocks.com/s/330726 now pls check .pls tell my mistake don’t change the entire code.
Hey @shrutikatyal
I don’t think u can k reverse it iteratively by only using loops.
Try to think of a recursive solution or iterative solution using stacks.
Algo for rec soln:
Algorithm :
- Reverse the first sub-list of size k.1.1 While reversing keep track of the next node and previous node.1.2 Let the pointer to the next node be next and pointer to the previous node be prev.
- head->next = reverse(next, k) /* Recursively call for rest of the list and link the two sub-lists */
- return prev /* prev becomes the new head of the list (see the diagrams of iterative method of this post) */