MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / main

Method main

Programs/RotateLinkedList.java:23–44  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

21 */
22public 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;

Callers

nothing calls this directly

Calls 4

buildLinkedListMethod · 0.95
rotateRightMethod · 0.95
printOutputMethod · 0.95
lengthMethod · 0.80

Tested by

no test coverage detected