Contents

조회 수 982 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
1113 System/OS 무선 인증 서버.. 김도.. ㅋㅋ file hooni 2013.04.23 17710
1112 System/OS 무료로 HTTPS 적용하기 (Lets' Encrypt) file hooni 2017.02.16 2397
1111 System/OS 무료로 HTTPS 적용하기 (Let's Encrypt) file hooni 2017.10.28 1704
1110 Develop 모터에 대한 pid 제어.. ㅎㅎ file hooni 2013.04.23 18942
1109 Etc 모바일 프로그래머가 갖추어야 할 필수 역량 file hooni 2017.02.16 1517
1108 System/OS 맥에서 포트 확인하고 닫기 (mac) hooni 2022.03.22 1241
1107 System/OS 맥에서 파일공유 (윈도우,맥) file hooni 2013.04.25 37405
1106 System/OS 맥북에서 MAC/윈도우 멀티부팅시 시간 설정 file hooni 2013.04.23 29878
1105 System/OS 맥 OS X 에서 스크린 화면 캡쳐 단축키 (Mac Print Screen) hooni 2015.07.21 2053
1104 Develop 링크들 보고 지울 내용 secret hooni 2019.11.21 0
1103 Develop 리팩토링 계획안 file hooni 2017.05.15 887
1102 Develop 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 file hooni 2013.04.23 81605
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98