> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/graph/hide-and-seek4-2.md).

# Hide and Seek4 2회차

재귀 함수 이용, 문제 복기

역으로 출력해야할 때 재귀함수 구현 방법

일단 뼈대부터 생각을 해보면\
print(int x) {\
&#x20; if(x==n) {x출력}\
&#x20; else{ print(from\[x]);}\
}

이렇게 1차로 생각했다. 그런데 매개변수 x가 n과 같을 때만 x가 출력되기 때문에, 재귀함수가 호출,실행된후 리턴되고 난 다음을 생각하지 못했다!\
from\[x]==n을 먼저 출력하고 나면 리턴되고 나서 현재의 함수에서 매개변수 x를 출력하고, 그 다음 재귀함수에서 x를 출력하는 방법으로 구현해준다!

![재귀함수 호출 구체화 및 도식화](https://3269900549-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MIbwNq54Ge4eqsziHM7%2F-McERG8NydbSB8M65aDR%2F-McEUWJPp1mhZkaemPuL%2Fimage.png?alt=media\&token=31557228-3c41-4d1a-80c5-47618ea93d3a)
