조회 수 2026 추천 수 0 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
155 Develop [php] Laravel 4. twitter bootstrap 적용하기 hooni 2018.04.05 4666
154 Develop [ios] SQLite 사용하기(튜토리얼) + 샘플코드 file hooni 2014.03.28 4623
153 Develop [ios] iOS에서 디바이스 종류 알아오기 hooni 2014.05.24 4608
152 Develop [php][laravel] 라라벨 프로젝트 생성 및 구조 file hooni 2017.12.15 4601
151 Develop [php][laravel] 초간단 MacOS에서 Laravel 개발 환경 구축 hooni 2017.12.15 4600
150 Develop [ios] URL 파라미터 파싱~ hooni 2014.05.12 4565
149 Develop macOS에 node, npm 설치하기 (homebrew) file hooni 2021.11.06 4554
148 Develop [ios] UILabel with two different color text hooni 2024.12.14 4545
147 Develop [js] jQuery 셀 병합 1 file hooni 2014.09.23 4510
146 Develop [ios] Sprite Kit & 사운드 재생시 백그라운드 진입시 앱이 비정상적으로 종료됨 hooni 2014.04.18 4489
145 Develop [ios] 아이폰에서 진동(Vibrate) 기능 추가하기 hooni 2014.04.18 4472
144 Develop [android] 딜레이를 구현하기 위한 꼼수 hooni 2016.11.24 4446
143 Develop [ios] UIWebView 캐쉬 삭제 hooni 2014.04.08 4432
142 Develop [ios] 유용한 매크로 hooni 2014.03.26 4428
141 Develop [iOS] Xcode 불필요한 캐시 삭제하기 hooni 2021.10.12 4403
140 Develop [js] Click button copy to clipboard hooni 2018.04.05 4400
Board Pagination Prev 1 ... 42 43 44 45 46 ... 53 Next
/ 53