Views 838 Votes 0 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

이진 탐색에 대한 두 가지 코드.


# 실행 조건

- 유일한 값들이어야 함 (중복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. [js] AngularJS 란?

    Date2015.11.26 CategoryDevelop Byhooni Views887
    Read More
  2. [ios] UIWebView에서 로컬에 있는 html 파일 불러오기

    Date2015.02.10 CategoryDevelop Byhooni Views893
    Read More
  3. [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export)

    Date2015.01.03 CategoryDevelop Byhooni Views894
    Read More
  4. [ios] iOS 8 개발자가 우선 알아야 할 3가지

    Date2014.10.02 CategoryDevelop Byhooni Views902
    Read More
  5. [js] 좋은 강연자료 & UI 자료

    Date2014.10.06 CategoryDevelop Byhooni Views909
    Read More
  6. [android] 딜레이를 구현하기 위한 꼼수

    Date2016.11.24 CategoryDevelop Byhooni Views936
    Read More
  7. [ubuntu] 우분투 18.04에 PHP5 설치하기

    Date2020.11.14 CategoryDevelop Byhooni Views941
    Read More
  8. [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법

    Date2017.03.29 CategoryDevelop Byhooni Views946
    Read More
  9. [ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기

    Date2015.02.10 CategoryDevelop Byhooni Views952
    Read More
  10. [ios] 상위 ViewController 가져오기

    Date2015.10.12 CategoryDevelop Byhooni Views956
    Read More
  11. [ios] 오브젝티브C→스위프트, 코드 변환 손쉽게

    Date2015.08.07 CategoryDevelop Byhooni Views959
    Read More
  12. [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태

    Date2018.10.19 CategoryDevelop Byhooni Views967
    Read More
  13. '2014 모바일 개발 트렌드' 발표자료입니다.

    Date2014.10.02 CategoryDevelop Byhooni Views980
    Read More
  14. [ios] Xcode의 디버그 모드에서 콜스택

    Date2015.01.03 CategoryDevelop Byhooni Views1002
    Read More
  15. [js] 스크롤 이벤트 막기

    Date2015.04.14 CategoryDevelop Byhooni Views1007
    Read More
  16. [c] FSN 온라인 코딩 테스트 (Sorting, Binary Search)

    Date2015.06.26 CategoryDevelop Byhooni Views1011
    Read More
Board Pagination Prev 1 3 4 5 6 7 ... 53 Next
/ 53