Develop
2015.06.26 16:35
[c] 이진 탐색 두 가지 코드 (재귀/반복)
조회 수 976 댓글 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; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
841 | Develop | '2014 모바일 개발 트렌드' 발표자료입니다. | hooni | 2014.10.02 | 1138 |
840 | Develop | Aspect Oriented Programming in Objective-C | hooni | 2015.05.18 | 949 |
839 | Develop | DDay Memo 1.9.4 소스코드 | hooni | 2015.10.03 | 0 |
838 | Develop | GCM 사용하기 2 (단말에 GCM 구현하기) | hooni | 2013.07.06 | 23412 |
837 | Develop | GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기) 4 | hooni | 2013.07.06 | 25428 |
836 | Develop | git 브런치 배우기 (링크) | hooni | 2013.07.09 | 20702 |
835 | Develop | GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스 | hooni | 2014.10.14 | 1267 |
834 | Develop | How to Test SMTP AUTH using Telnet | hooni | 2018.04.05 | 1590 |
833 | Develop | JSON, BSON 변환 | hooni | 2013.04.23 | 11874 |
832 | Develop | Laravel 5 Failed opening required bootstrap/../vendor/autoload.php | hooni | 2018.01.24 | 1836 |
831 | Develop | Mac OS 에 Jenkins 설치하기 (Homebrew) 2 | hooni | 2017.03.15 | 8398 |
830 | Develop | macOS에 node, npm 설치하기 (homebrew) | hooni | 2021.11.06 | 1460 |