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; }
-
'2014 모바일 개발 트렌드' 발표자료입니다.
-
Aspect Oriented Programming in Objective-C
-
DDay Memo 1.9.4 소스코드
-
GCM 사용하기 2 (단말에 GCM 구현하기)
-
GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기)
-
git 브런치 배우기 (링크)
-
GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스
-
How to Test SMTP AUTH using Telnet
-
JSON, BSON 변환
-
Laravel 5 Failed opening required bootstrap/../vendor/autoload.php
-
Mac OS 에 Jenkins 설치하기 (Homebrew)
-
macOS에 node, npm 설치하기 (homebrew)