Contents

조회 수 949 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
517 Develop [c] 압축 알고리즘 소스 및 정리 file hooni 2013.04.23 8787
516 Develop [c] OpenGL 시어핀스키 가스킷(p.73 - 첫시간) hooni 2003.04.23 8771
515 Develop [c] 캘린더 양음 변환 함수 hooni 2003.04.23 8770
514 Develop [c++] 중복실행 방지(Mutex;뮤텍스 ) 샘플 소스.. ㅋㅋ file hooni 2013.04.23 8755
513 Develop [c] OpenGL 마우스 이벤트 hooni 2003.04.23 8751
512 Develop [asem] CMOS 패스워드 알아내기.. 소스.. file hooni 2003.04.23 8748
511 Develop [php] 초간단 게시판 페이지 분할 알고리즘 hooni 2003.04.23 8747
510 Develop [asp] 문자열 넘겨받기 (get,post) hooni 2013.04.23 8740
509 Develop [java] Interface 와 abstract hooni 2013.04.23 8721
508 Develop [js] Text 중 URL 형식을 인식해 단축 URL로 변경 file hooni 2013.04.23 8720
507 Develop [css] 화면 스크롤 제어 ㅋㅋ hooni 2003.04.23 8702
506 Develop [c++] namespace 사용 예 hooni 2003.04.23 8698
Board Pagination Prev 1 ... 23 24 25 26 27 28 29 30 31 32 ... 71 Next
/ 71