(String[] args)
| 21 | */ |
| 22 | public class RotateLinkedList { |
| 23 | public static void main(String[] args) { |
| 24 | try (Scanner sc = new Scanner(System.in)) { |
| 25 | System.out.println("Enter the LinkedList in the form of [1,2,3,4,5]"); |
| 26 | String input = sc.nextLine(); |
| 27 | System.out.println("Enter the number of rotations"); |
| 28 | int k = sc.nextInt(); |
| 29 | String str = input.replaceAll(" ", "") .substring(1, input.length() - 1); |
| 30 | String[] nodesStr = str.split(","); |
| 31 | if (nodesStr.length == 0) { |
| 32 | System.out.println("[]"); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | SinglyLinkedNode head = buildLinkedList(nodesStr); |
| 37 | RotateLinkedList solution = new RotateLinkedList(); |
| 38 | SinglyLinkedNode newHead = solution.rotateRight(head, k); |
| 39 | printOutput(newHead); |
| 40 | } catch (Exception e) { |
| 41 | System.out.println( |
| 42 | "Something went wrong. Check the linkedlist format is in the form of [1,2,3,4,5] and rotation is an integer"); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | private static SinglyLinkedNode buildLinkedList(String[] nodesStr) { |
| 47 | SinglyLinkedNode head = null; |
nothing calls this directly
no test coverage detected