Contents

조회 수 980 댓글 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;
}


?

  1. [ios] ViewController Push할 때 애니메이션 효과

    Date2015.10.23 CategoryDevelop Byhooni Views1003
    Read More
  2. 개인적으로 쓰고 있는 bash_profile

    Date2015.01.16 CategorySystem/OS Byhooni Views1001
    Read More
  3. [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export)

    Date2015.01.03 CategoryDevelop Byhooni Views1000
    Read More
  4. [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보

    Date2020.12.15 CategoryDevelop Byhooni Views997
    Read More
  5. [js] 좋은 강연자료 & UI 자료

    Date2014.10.06 CategoryDevelop Byhooni Views997
    Read More
  6. 수리통계학 : 표본공간과 사상-1

    Date2015.04.20 CategoryEtc Byhooni Views995
    Read More
  7. [ppt] iOS 플라랩#02(2015.03.19) 발표 자료

    Date2015.04.24 CategoryPPT Byhooni Views994
    Read More
  8. [android] AlertDialog 메시지 창 띄우기

    Date2015.07.09 CategoryDevelop Byhooni Views992
    Read More
  9. [ios] iOS 8 개발자가 우선 알아야 할 3가지

    Date2014.10.02 CategoryDevelop Byhooni Views992
    Read More
  10. [ppt] Information Security 발표 자료 (@Team Study 2012.11.15)

    Date2015.07.22 CategoryPPT Byhooni Views987
    Read More
  11. [macos] How to Fix ‘You Shut Down Your Computer Because of a Problem’

    Date2022.06.01 CategorySystem/OS Byhooni Views983
    Read More
  12. [ios] UIWebView에서 로컬에 있는 html 파일 불러오기

    Date2015.02.10 CategoryDevelop Byhooni Views983
    Read More
Board Pagination Prev 1 ... 86 87 88 89 90 91 92 93 94 95 ... 98 Next
/ 98