MCPcopy Create free account
hub / github.com/careercup/ctci / main

Method main

java/Chapter 2/Question2_7/Question.java:44–65  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

42 }
43
44 public static void main(String[] args) {
45 int length = 10;
46 LinkedListNode[] nodes = new LinkedListNode[length];
47 for (int i = 0; i < length; i++) {
48 nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
49 }
50
51 for (int i = 0; i < length; i++) {
52 if (i < length - 1) {
53 nodes[i].setNext(nodes[i + 1]);
54 }
55 if (i > 0) {
56 nodes[i].setPrevious(nodes[i - 1]);
57 }
58 }
59 // nodes[length - 2].data = 9; // Uncomment to ruin palindrome
60
61 LinkedListNode head = nodes[0];
62 System.out.println(head.printForward());
63 Question q = new Question();
64 System.out.println(q.isPalindrome(head));
65 }
66
67}

Callers

nothing calls this directly

Calls 4

printForwardMethod · 0.95
isPalindromeMethod · 0.95
setPreviousMethod · 0.80
setNextMethod · 0.45

Tested by

no test coverage detected