Develop
2015.06.26 16:35
[c] 이진 탐색 두 가지 코드 (재귀/반복)
조회 수 852 댓글 0
첨부 '1' |
---|
이진 탐색에 대한 두 가지 코드.
# 실행 조건
- 유일한 값들이어야 함 (중복x).
- 오름차순 정렬 후 실행해야 함.
# 구현 방식
- 재귀함수 (bsearch_recursive)
- while 반복문 (bsearch_loop)
#include <stdio.h> #include "bsearch.c" void bbsort(int *arr, int length); int bsearch_recursive(int *arr, int begin, int end, int target); int bsearch_loop(int *arr, int target, int length); int main( ) { int arr[] = {11, 9, 1, 5, 15, 3, 7, 13}; int target = 7; int result; int length; length = sizeof(arr)/sizeof(int); bbsort(arr, length); //By Recursive result = bsearch_recursive(arr, 0, length-1, target); //By Loop result = bsearch_loop(arr, length, target); if(result == -1) { printf("Not Found. "); } else { for( int i=0 ; i<length ; ++i ) { printf( "%d ", arr[i] ); } printf(" Found Index : %d. ", result); } return 0; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
81 | Develop | [android] 개발 환경 세팅 따라하기 ㅋㅋ | hooni | 2013.04.23 | 40409 |
80 | Develop | [android] 간단한 SQLIite 예제 | hooni | 2017.06.14 | 1346 |
79 | Develop | [android] 가속도 센서를 이용한 흔듦(Shake) 감지 | hooni | 2014.11.04 | 1902 |
78 | Develop | [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) | hooni | 2013.04.23 | 20426 |
77 | PPT | [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 | hooni | 2013.04.23 | 75646 |
76 | Develop | [android] SurfaceView를 이용한 애니메이션 ㅎㅎ | hooni | 2013.04.23 | 57715 |
75 | Develop | [android] SQLiteOpenHelper를 이용한 DBManager | hooni | 2017.06.14 | 2083 |
74 | Develop | [android] N-Puzzle 게임 | hooni | 2015.07.09 | 876 |
73 | Develop | [android] ListView+ArrayAdapter 테스트 | hooni | 2013.04.23 | 43906 |
72 | Develop | [android] keytool을 사용하여 키스토어 생성 | hooni | 2013.04.23 | 69520 |
71 | Develop | [android] How can I place app icon on launcher home screen? | hooni | 2016.11.15 | 1279 |
70 | Develop | [android] GCM 사용하기 1 (GCM 서비스 신청하기) | hooni | 2013.07.06 | 51359 |