@Test public void shouldReturnTheSameNodeInTheListIfTheTreeJustContainsOneElementWithoutExtraDataStructure() { BinaryNode<Integer> root = new BinaryNode<Integer>(0); List<BinaryNode> result = binaryTreeByLevel.getWithoutAdditionalDataStructures(root); List<BinaryNode<Integer>> expectedList = Arrays.asList(root); assertEquals(expectedList, result); }
public List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); int depth = getDepth(root); for (int i = 1; i <= depth; i++) { result.addAll(getNodesForLevel(root, i)); } return result; }
BinaryTreeByLevel { public List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); int depth = getDepth(root); for (int i = 1; i <= depth; i++) { result.addAll(getNodesForLevel(root, i)); } return result; } }
BinaryTreeByLevel { public List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); int depth = getDepth(root); for (int i = 1; i <= depth; i++) { result.addAll(getNodesForLevel(root, i)); } return result; }  }
BinaryTreeByLevel { public List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); int depth = getDepth(root); for (int i = 1; i <= depth; i++) { result.addAll(getNodesForLevel(root, i)); } return result; }  List<BinaryNode> getUsingQueue(BinaryNode root); List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root); }
BinaryTreeByLevel { public List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); int depth = getDepth(root); for (int i = 1; i <= depth; i++) { result.addAll(getNodesForLevel(root, i)); } return result; }  List<BinaryNode> getUsingQueue(BinaryNode root); List<BinaryNode> getWithoutAdditionalDataStructures(BinaryNode root);  }