Contents

Views 2022 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
205 Develop [js] 동적(innerHTML)으로 자바스크립트 실행하기.. 2 file hooni 2013.04.23 19410
204 System/OS [linux] 패킷의 소스 주소 바꾸기 hooni 2003.04.23 19535
203 System/OS [linux] CentOS 터미널 언어 설정(한글/영어) hooni 2013.12.22 19554
202 Develop [ios] NSString 간단한 정규식 사용법 hooni 2014.01.28 19573
201 Develop [ios] 앱에서 다른 앱 실행시키기 file hooni 2013.09.05 19688
200 Develop 모터에 대한 pid 제어.. ㅎㅎ file hooni 2013.04.23 19726
199 PPT [doc] 인공지능 관련 자료(채팅로봇도 포함..) file hooni 2013.04.23 19731
198 System/OS 해커스랩 깨기.. 후후.. ㅋㅋ file hooni 2013.04.23 19807
197 Develop URI 인코딩, URL 인코딩 file hooni 2013.04.23 19818
196 Develop [java] 입출력 스트림 3부 (오브젝트) hooni 2013.04.23 19892
195 Develop [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens) file hooni 2013.04.23 20043
194 System/OS [linux] APM(apache, php, mysql) + gd 설치순서.. hooni 2003.04.23 20064
Board Pagination Prev 1 ... 77 78 79 80 81 82 83 84 85 86 ... 99 Next
/ 99