Clockwise rotation of linked list
Given a linked list which include N nodes. And given a number K which indicates clockwise direction to rotate linked list node. Our goal is to rotate linked list nodes in clockwise.

Example 1
Input : 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → NULL
Given k : 3
Output : 4 → 5 → 6 → 7 → 8 → 1 → 2 → 3 → NULL
Example 2
Input : 4 → 9 → 7 → 3 → 8 → 6 → -2 → NULL
Given k : 18
Output : 8 → 6 → -2 → 4 → 9 → 7 → 3 → NULL
[
Note :
1) k is larger the number of linked list node.
First 7 rotation
4 → 9 → 7 → 3 → 8 → 6 → -2 → NULL [7 rotation]
Second 7 rotation
4 → 9 → 7 → 3 → 8 → 6 → -2 → NULL [14 rotation]
Next 4 rotation
8 → 6 → -2 → 4 → 9 → 7 → 3 → NULL [18 rotation]
Hint : use modulo operator to get final rotation
]
Here given code implementation process.
-
1) Rotate linked list clockwise by k nodes in java
2) Rotate linked list clockwise by k nodes in c++
3) Rotate linked list clockwise by k nodes in c
4) Rotate linked list clockwise by k nodes in golang
5) Rotate linked list clockwise by k nodes in c#
6) Rotate linked list clockwise by k nodes in vb.net
7) Rotate linked list clockwise by k nodes in php
8) Rotate linked list clockwise by k nodes in node js
9) Rotate linked list clockwise by k nodes in python
10) Rotate linked list clockwise by k nodes in ruby
11) Rotate linked list clockwise by k nodes in scala
12) Rotate linked list clockwise by k nodes in swift
13) Rotate linked list clockwise by k nodes in kotlin
14) Rotate linked list clockwise by k nodes in typescript
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment