@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullListInstances() { getTheElementInTheMiddleOfTheList.get(null); }
public ListNode<Integer> get(ListNode<Integer> list) { validateInput(list); int size = getListSize(list); int middleElementPosition = size % 2 != 0 ? size / 2 : (size / 2) - 1; ListNode middleElement = list; for (int i = 0; i < middleElementPosition; i++) { middleElement = middleElement.getNext(); } return middleElement; }
GetTheElementInTheMiddleOfTheList { public ListNode<Integer> get(ListNode<Integer> list) { validateInput(list); int size = getListSize(list); int middleElementPosition = size % 2 != 0 ? size / 2 : (size / 2) - 1; ListNode middleElement = list; for (int i = 0; i < middleElementPosition; i++) { middleElement = middleElement.getNext(); } return middleElement; } }
GetTheElementInTheMiddleOfTheList { public ListNode<Integer> get(ListNode<Integer> list) { validateInput(list); int size = getListSize(list); int middleElementPosition = size % 2 != 0 ? size / 2 : (size / 2) - 1; ListNode middleElement = list; for (int i = 0; i < middleElementPosition; i++) { middleElement = middleElement.getNext(); } return middleElement; }  }
GetTheElementInTheMiddleOfTheList { public ListNode<Integer> get(ListNode<Integer> list) { validateInput(list); int size = getListSize(list); int middleElementPosition = size % 2 != 0 ? size / 2 : (size / 2) - 1; ListNode middleElement = list; for (int i = 0; i < middleElementPosition; i++) { middleElement = middleElement.getNext(); } return middleElement; }  ListNode<Integer> get(ListNode<Integer> list); ListNode<Integer> get2(ListNode<Integer> list); }
GetTheElementInTheMiddleOfTheList { public ListNode<Integer> get(ListNode<Integer> list) { validateInput(list); int size = getListSize(list); int middleElementPosition = size % 2 != 0 ? size / 2 : (size / 2) - 1; ListNode middleElement = list; for (int i = 0; i < middleElementPosition; i++) { middleElement = middleElement.getNext(); } return middleElement; }  ListNode<Integer> get(ListNode<Integer> list); ListNode<Integer> get2(ListNode<Integer> list);  }