Contents

조회 수 838 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
369 [ios] 인앱결제 & 오토레이아웃 관련 강좌 secret hooni 2013.11.14 0
368 Develop [java] 초간단 싱글톤(Singleton) 패턴 샘플 코드 file hooni 2013.11.18 11595
367 Develop [php] php5.3부터는 eregi()대신 preg_match()를 사용 hooni 2013.11.18 12470
366 Develop [js] window.open() 속성 사용 방법 hooni 2013.11.18 13590
365 Develop [ios] iphone SetDeviceOrientation 화면 강제 회전 hooni 2013.11.20 18460
364 Develop [ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업) file hooni 2013.11.20 14510
363 Develop [ios] iOS In App Purchase #2 (코드 구현) file hooni 2013.11.20 13768
362 Develop [ios] iOS In App Purchase 코드 부분 샘플 1 hooni 2013.11.20 11760
361 Develop [ios] iOS In App Purchase 코드 부분 샘플 2 hooni 2013.11.20 11276
360 Develop [ios] In App Purchase 개발 hooni 2013.11.20 9264
359 Develop 이어서 작업할 내용~ secret hooni 2013.11.21 0
358 Etc [english] 영어공부 혼자 하기, 인터넷으로 영어공부하기 추천사이트 20선 file hooni 2013.11.25 9408
Board Pagination Prev 1 ... 63 64 65 66 67 68 69 70 71 72 ... 98 Next
/ 98