Contents

조회 수 2026 댓글 0
Atachment
첨부 '1'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

이진 탐색에 대한 두 가지 코드.


# 실행 조건

- 유일한 값들이어야 함 (중복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;
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
373 Develop [js] IE에서 인쇄 설정 팁 hooni 2013.04.23 11947
372 Etc [php] 싸이월드 이미지 외부 링크 하기(php) hooni 2013.04.23 17621
371 System/OS [doc] 피쳐셀렉션(feature selection using..) 발표 자료 file hooni 2013.04.23 13530
370 System/OS [doc] 네트워크 장비와 라우터 설정 방법 발표 자료 file hooni 2013.04.23 15209
369 System/OS [windows] 인터넷 익스플로러(IE) 도구모음 표시줄에 아이콘 추가 file hooni 2013.04.23 19089
368 System/OS [windows] 종료, 재시작, 로그아웃 아이콘 만들기 hooni 2013.04.23 19079
367 System/OS [router] 설정과 기본 명령어들 모음 hooni 2013.04.23 16451
366 System/OS NAT와 DHCP에 대한 간단한 설명 hooni 2013.04.23 19152
365 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9943
364 Etc [flash] 맘에 드는 파이차트 file hooni 2013.04.23 13587
363 Develop [web] 웹 연동 프로그램 모음.. file hooni 2013.04.23 7961
362 System/OS [doc] TCP/IP 강의 자료 (html) file hooni 2013.04.23 11944
Board Pagination Prev 1 ... 63 64 65 66 67 68 69 70 71 72 ... 99 Next
/ 99