Contents

Views 2033 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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


# 실행 조건

- 유일한 값들이어야 함 (중복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
No. Category Subject Author Date Views
759 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 5064
758 Develop [c] 셀프 넘버(Self Number) 구하기 1 hooni 2016.09.09 3833
757 Develop [android] Android N requires the IDE to be running with Java 1.8 or later 오류 hooni 2016.08.30 2788
756 Develop [c] 파일명 또는 특정 패턴을 적용 file hooni 2016.08.03 2412
755 Develop [ios] Crashlytics, Fabfic 설치/설정 hooni 2016.07.21 2367
754 Develop [ios] 새로 만들고 있는 DateMemo file hooni 2016.07.12 1903
753 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 14312
752 Develop [ios][swift] 초간단 To-do Memo file hooni 2016.06.27 11041
751 Develop [ios][swift] 초간단 TableView 샘플 file hooni 2016.06.27 5291
750 Develop [ios] 웹뷰 history.back() ㅋㄷ file hooni 2016.06.27 5674
749 Develop [ios] 기본 네비게이션바의 타이틀, back버튼 위치와 속성 변경 file hooni 2016.05.16 5180
748 Develop [ios] UUID 생성 + Key Chain 연동 file hooni 2016.05.13 10196
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 71 Next
/ 71