int BSearch(int ar[], int frist, int last, int target){
//탈출조건
if(first > last)
return -1;
int mid = (first + last)/2;
if(ar[mid] == target)
return mid;
if(ar[mid] < target)
BSearch(ar, first, mid-1, target);
else
BSearch(ar, mid+1, last, target);
}
원반은 한번에 하나씩만 옮길 수 있고 작은 원반 위에 큰 원반이 올라갈 수 없음
A에 있는 n개의 워반을 C로 옮긴다고 할 때
//n개를 from에서 by를 경유해 to로 이동
void HanoiMove(int num, char from, char by, char to){
if(num == 1)
pritntf("원반1을 %c에서 %c로 이동 \n", from, to);
else{
HanoiMove(num-1, from, to, by); //n-1개를 from에서부터 to를 거쳐 by로 이동
printf("원반 %d를 %c에서 %c로 이동 \n", num, from, to);
HanoiMove(num-1, by, from, to); //n-1개를 by에서부터 from을 거쳐 to로 이동
}
}
void main(){
//막대 A에 있는 원반을 B를 경유해 C로 이동
HanoiMove(3, 'A', 'B', 'C');
}