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
153 Develop [c++] 트리컨트롤 스텝 3 예제.. file hooni 2013.04.23 7945
152 Develop [c++] 트리컨트롤 스텝 2 예제.. file hooni 2013.04.23 6955
151 Develop [c++] 템플릿(Template) 예제 소스.. file hooni 2013.04.23 6978
150 Develop [c++] 초간단 스택 두 가지 방식(class, struct) file hooni 2013.04.23 7553
149 Develop [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ file hooni 2013.04.23 8878
148 Develop [c++] 중복실행 방지(Mutex;뮤텍스 ) 샘플 소스.. ㅋㅋ file hooni 2013.04.23 8737
147 Develop [c++] 자료구조(링크리스트,스택,큐)와 후위 표기 계산기 샘플 ㅋㅋ 4 file hooni 2013.04.23 12318
146 Develop [c++] 인라인 함수에 대한 설명 hooni 2013.04.23 7110
145 Develop [c++] 인라인 함수 설명과 예제.. file hooni 2013.04.23 6633
144 Develop [c++] 윈도우 프로세스뷰어 분석.. ㅋㅋ file hooni 2013.04.23 8836
143 Develop [c++] 윈도우 API 정복 예제 file hooni 2013.04.23 7608
142 Develop [c++] 웹폼(webform)전송과 http 파일 업로드 샘플 file hooni 2013.04.23 33070
141 Develop [c++] 압축프로그램(Lite Zip) 샘플 file hooni 2013.04.23 8603
140 Develop [c++] 쓰레드(Thread) 객체의 사용 hooni 2013.04.23 8576
139 Develop [c++] 소켓 프로그래밍 관련 링크.. (퍼올려고 올린거) hooni 2013.04.23 7029
138 Develop [c++] 바탕화면 테두리에 자석처럼 붙는 스냅효과.. file hooni 2013.04.23 8902
Board Pagination Prev 1 ... 42 43 44 45 46 ... 53 Next
/ 53