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;
}


?

  1. [ios] iOS 앱 아이콘을 만드는 유틸

    Date2015.01.03 CategoryDevelop Byhooni Views863
    Read More
  2. [android] N-Puzzle 게임

    Date2015.07.09 CategoryDevelop Byhooni Views859
    Read More
  3. XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그

    Date2016.04.21 CategoryDevelop Byhooni Views858
    Read More
  4. [android] AlertDialog 메시지 창 띄우기

    Date2015.07.09 CategoryDevelop Byhooni Views849
    Read More
  5. [ios] 문자열로 함수 실행하기 (eval 함수처럼)

    Date2015.02.10 CategoryDevelop Byhooni Views845
    Read More
  6. [ios] URL 랜딩 속도(OpenURL 10초 정지되는) 이슈

    Date2015.02.09 CategoryDevelop Byhooni Views843
    Read More
  7. [ios] Thread Loop 내에서 UI 업데이트 방법

    Date2015.01.03 CategoryDevelop Byhooni Views841
    Read More
  8. [ios] 아이폰 앱 이름 및 버전 정보

    Date2015.03.24 CategoryDevelop Byhooni Views838
    Read More
  9. [c] 이진 탐색 두 가지 코드 (재귀/반복)

    Date2015.06.26 CategoryDevelop Byhooni Views838
    Read More
  10. [ios] NSString, RegularExpression Find/Replace

    Date2017.04.14 CategoryDevelop Byhooni Views828
    Read More
  11. [ios] 비동기 블럭 코드 예제

    Date2014.11.21 CategoryDevelop Byhooni Views823
    Read More
  12. [ios] GMT Date와 Local Date 변환하기

    Date2015.04.07 CategoryDevelop Byhooni Views821
    Read More
Board Pagination Prev 1 ... 61 62 63 64 65 66 67 68 69 70 71 Next
/ 71