Views 838 Votes 0 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
101 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 47514
100 PPT [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) file hooni 2013.04.23 37851
99 Develop [android] 화면 전환(가로/세로)시 설정 hooni 2013.04.23 43371
98 Develop [android] 해상도 관련 팁 (dip -> pixel 변환) hooni 2013.04.23 15333
97 Develop [android] 코드에서 문자열로 Resource 가져오기 hooni 2015.07.09 3936
96 Develop [android] 초간단 얼럿 (AlertDialog) hooni 2016.10.21 807
95 System/OS [android] 초간단 HTTP, POST 전송 샘플 1 file hooni 2017.02.16 3448
94 PPT [Android] 제스처 자료.. file hooni 2013.05.28 51072
93 Develop [android] 점심 해결 앱 소스 코드 ㅋㅋ file hooni 2013.04.23 76396
92 Develop [android] 자동차 리모컨 소스코드 secret hooni 2013.04.23 17082
91 Develop [android] 안드로이드 어플 모음 ㅎㅎ secret hooni 2013.04.23 16340
90 Develop [android] 안드로이드 앱 문서 샘플 - NCComix file hooni 2017.07.11 2103
89 Develop [android] 안드로이드 동영상 스트리밍 예제 2 hooni 2015.01.02 4812
88 Develop [android] 버전 별 앱 알림 설정으로 이동하는 방법 file hooni 2016.11.28 2157
87 Develop [android] 멀티터치(Multi touch) 부분 구현 ㅋㅋ file hooni 2013.04.23 27415
86 Develop [android] 만화 어플 소스코드 file hooni 2013.04.23 92836
Board Pagination Prev 1 ... 66 67 68 69 70 ... 74 Next
/ 74