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
번호 분류 제목 글쓴이 날짜 조회 수
61 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 668
60 Develop [switch] 시스코 스위치(catalyst 2950) telnet 설정 hooni 2013.04.23 11269
59 Develop [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 hooni 2013.04.23 11386
58 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 934
57 Develop [unix] Java 애플릿용 HTML 자동 생성 hooni 2014.02.19 8210
56 Develop [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값) hooni 2013.04.23 14796
55 Develop [unix] 로그파일 정리 쉘스크립트 hooni 2014.02.19 10799
54 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 14949
53 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 11245
52 Develop [vbs] CD롬 뱉는 스크립트.. hooni 2003.04.23 11699
51 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 8183
50 Develop [vb] 문자열에서 태그 제거함수 (Visual Basic) file hooni 2013.04.23 22619
Board Pagination Prev 1 ... 61 62 63 64 65 66 67 68 69 70 71 Next
/ 71