Develop
2015.06.26 16:35
[c] 이진 탐색 두 가지 코드 (재귀/반복)
조회 수 2026 댓글 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; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1069 | System/OS | [linux] Oracle8.1.6, Mysql+PHP+Zend Optimizer+APACHE+Tomcat(jsp,servlet)+IMAP+gd | hooni | 2003.04.23 | 33287 |
1068 | System/OS | [linux] 특수문자 환경 설정(stty) | hooni | 2003.04.23 | 16117 |
1067 | System/OS | [linux] 메타(기호)문자의 의미와 사용 | hooni | 2003.04.23 | 17267 |
1066 | System/OS | [linux] 프로세스 상태확인(ps) | hooni | 2003.04.23 | 13544 |
1065 | System/OS | [linux] 종료와 종료코드 확인(환경변수에서) | hooni | 2003.04.23 | 16903 |
1064 | System/OS | [linux] 셀 스크립트 if, for, case in.. | hooni | 2003.04.23 | 14493 |
1063 | System/OS | [linux] 스케쥴링 순서(nice) 변경하기 | hooni | 2003.04.23 | 13376 |
1062 | System/OS | [linux] 기존 환경설정 저장하면서 커널 컴파일.. | hooni | 2003.04.23 | 14444 |
1061 | System/OS | [linux] Proftpd 설치 가이드 | hooni | 2003.04.23 | 13845 |
1060 | Develop |
[c] 간단한 자료구조(stack, queue, linked list) 구현 소스
6 ![]() |
hooni | 2003.04.23 | 11496 |
1059 | Develop |
[c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드
1 ![]() |
hooni | 2003.04.23 | 13403 |
1058 | Develop |
[c] 테트리스(Tetris) 게임(도스용) 소스코드
![]() |
hooni | 2003.04.23 | 12780 |