Contents

Views 838 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
369 System/OS [linux] wget 명령 사용 예제 hooni 2020.05.26 1434
368 System/OS [linux] Xwindow/Xmanager 사용 hooni 2003.04.23 13334
367 System/OS [linux] X환경 GNOME에서 KDE로 바꾸는 법.. hooni 2013.04.23 12365
366 System/OS [linux] yum 업데이트 시 커널 제외하기 hooni 2014.09.11 1258
365 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9111
364 System/OS [linux] 간단한 NAT 설정 script hooni 2003.04.23 12597
363 System/OS [linux] 간단한 vi편집기 사용 명령 hooni 2003.04.23 13456
362 System/OS [linux] 계정관리하기(내공쌓기) hooni 2003.04.23 13157
361 System/OS [linux] 기본 명령어 (내공쌓기) hooni 2003.04.23 14333
360 System/OS [linux] 기본적인 설정하기(내공쌓기) hooni 2003.04.23 13993
359 System/OS [linux] 기존 환경설정 저장하면서 커널 컴파일.. hooni 2003.04.23 13458
358 System/OS [linux] 꿀통(honeyd) 설치하기.. 메뉴얼 과정 6 file hooni 2006.04.23 20219
Board Pagination Prev 1 ... 63 64 65 66 67 68 69 70 71 72 ... 98 Next
/ 98