Develop
2015.06.26 16:35
[c] 이진 탐색 두 가지 코드 (재귀/반복)
조회 수 961 댓글 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; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
93 | Develop | [펌] 게임 엔진 만든거 공개합니다. | hooni | 2015.02.21 | 2461 |
92 | System/OS |
[펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들
![]() |
hooni | 2020.10.15 | 1102 |
91 | Etc | 개발자가 알아야할 10가지 보안팁으로 코드 보호하기 | hooni | 2013.04.23 | 16447 |
90 | System/OS | 개인적으로 쓰고 있는 bash_profile | hooni | 2015.01.16 | 981 |
89 | System/OS | 개인적으로 쓰고 있는 zshrc 파일 | hooni | 2022.02.25 | 995 |
88 | Develop |
객체지향 프로그래밍에 대한 개념.. (객체)
![]() |
hooni | 2013.04.23 | 7337 |
87 | System/OS | 나중에 해봐야지.. libconv 설치.. ㅡ,.ㅡ; | hooni | 2013.04.23 | 19336 |
86 | PPT |
네오웹 세미나 자료~
![]() |
hooni | 2013.05.28 | 0 |
85 | System/OS |
네트워크 용어 정리
![]() |
hooni | 2022.11.20 | 1577 |
84 | System/OS | 네트워크별 MTU(최대 전송 단위) | hooni | 2013.04.23 | 17707 |
83 | Develop |
논문 실험용 고려대 툴바 ㅎㅎ
![]() |
hooni | 2013.04.23 | 8686 |
82 | Etc |
논문(BHO)에 들어갈 내용 집에가서 테스트 해볼 것..
![]() |
hooni | 2013.05.28 | 10230 |