Contents

조회 수 976 댓글 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 [android] 만화 어플 소스코드 file hooni 2013.04.23 92923
516 Develop [ios] 미스터피자(Mr.pizza) 어플 file hooni 2013.04.23 42693
515 Develop [iphone] 아이폰 어플 모음 ㅋㅋ secret hooni 2013.04.23 13707
514 Develop [android] 안드로이드 어플 모음 ㅎㅎ secret hooni 2013.04.23 16340
513 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 33585
512 Develop [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드) file hooni 2013.04.23 72040
511 Develop [c#] Hashtable <-> Json (dll 포함) file hooni 2013.04.23 80727
510 Develop [c#] Json 라이브러리 (System.Net.Json.dll) file hooni 2013.04.23 58585
509 Develop [c#] 간단한 IPC 통신 예제 hooni 2013.04.23 63776
508 Develop [c#] 간단한 소켓통신 예제.. hooni 2013.04.23 26737
507 Develop [c#] 비동기 통신 샘플 코드 ㅎㅎ file hooni 2013.04.23 23696
506 Develop [c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ secret hooni 2013.04.23 7651
Board Pagination Prev 1 ... 23 24 25 26 27 28 29 30 31 32 ... 71 Next
/ 71