Created
October 31, 2019 18:41
-
-
Save libliboom/9e395cf1849c98e269d09243cea37b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 반환 결과값이 단순한 경우 | |
int size() { | |
int result = 1; | |
for (Node each : getChildren()) | |
result += each.size(); | |
return result; | |
} | |
// 파라미터를 전달해서 결과를 수집하는 직관적인 경우 | |
asList() { | |
List results = new ArrayList(); | |
addTo(results); | |
return results; | |
} | |
addTo(List elements) { | |
elements.add(getValue()); | |
for (Node each : getChildren()) | |
each.addTo(elements); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment