Develop
2015.06.26 16:35
[c] 이진 탐색 두 가지 코드 (재귀/반복)
조회 수 2023 댓글 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; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
735 | Develop | [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) | hooni | 2013.04.23 | 22610 |
734 | Develop |
[c] 포인터 학습용 예제 소스 코드
![]() |
hooni | 2013.04.23 | 22217 |
733 | Develop | [c] home env stack overflow | hooni | 2003.04.23 | 22148 |
732 | Develop | git 브런치 배우기 (링크) | hooni | 2013.07.09 | 22079 |
731 | Develop |
[opengl] 컴퓨터 그래픽스 강의 자료(수업자료)
![]() |
hooni | 2003.04.23 | 22052 |
730 | Develop | [php] substr() 한글 자를 때 깨짐 방지 | hooni | 2014.01.09 | 21530 |
729 | Develop |
[python] 애니팡, 캔디팡 매크로
![]() |
hooni | 2013.09.06 | 21426 |
728 | Develop |
[ios] libxml/tree.h file not found
![]() |
hooni | 2013.08.08 | 21280 |
727 | Develop |
[c] UTF-8을 EUC-KR로 변환.. (iconv)
![]() |
hooni | 2013.04.23 | 21279 |
726 | Develop | [php] XE 에서 php 구문 사용하기 (XE 템플릿에서) | hooni | 2013.10.31 | 21128 |
725 | Develop | [js]모바일 웹에서 orientationchange | hooni | 2013.04.23 | 20852 |
724 | Develop |
[c] AES 알고리즘 (암호화/복호화)
![]() |
hooni | 2003.04.23 | 20839 |