이번에 인턴 사원 멘토링을 맡게 되면서 교육을 진행하고 있는데 재귀함수에 대해서는 잘 이해를 못하는 것 같아 시퀀스 다이어그램을 그려보았다.
재귀함수를 어떻게 그리면 좋을까 생각한 끝에 아래와 같은 결과물이 나왔는데 인턴 사원이 잘 이해할 수 있을랑가 모르겠다.
[시퀀스 다이어그램]
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
package algorithm; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
import java.io.File; | |
import org.junit.Test; | |
/** | |
* @FileName : RecursiveTest.java | |
* @Project : test_project | |
* @Date : 2013. 7. 5. | |
* @작성자 : 이남규 | |
* @프로그램설명 : | |
*/ | |
public class RecursiveTest { | |
/** | |
* <pre> | |
* recursiveFile | |
* 디렉토리 안에 있는 파일 갯수 추출 | |
* <pre> | |
* @param file | |
* @param totalCnt | |
* @return | |
*/ | |
public int recursiveFile(File file) { | |
// 파일인 경우 | |
if (file.isFile()) { | |
return 1; | |
} | |
int totalCnt = 0; | |
String[] fileList = file.list(); | |
for (String childFile : fileList) { | |
totalCnt += recursiveFile(new File(file, childFile)); | |
} | |
return totalCnt; | |
} | |
@Test | |
public void test() { | |
assertThat(3, is(recursiveFile(new File("E:\\test\\recursive")))); | |
} | |
} |
'프로그래밍' 카테고리의 다른 글
리눅스에서 java 컴파일 및 실행 하기 (4) | 2013.08.09 |
---|---|
Mockito를 이용한 테스트 (0) | 2013.08.07 |
Serializable 객체직렬화 (2) | 2013.07.30 |
jquery를 이용한 jsonp 처리 방법 (0) | 2013.07.11 |
369 게임 알고리즘 (0) | 2013.06.26 |
java default 접근 제어자 활용 범위? (0) | 2013.06.13 |
정규표현식 (Java) (2) | 2013.05.09 |
스프링 시큐리티 적용하기 (properties 인증 방법) (2) | 2013.04.20 |