Contents

조회 수 844 댓글 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. [js] One Time Pad key generatorㅡ.,ㅡ;

    Date2013.04.23 CategoryDevelop Byhooni Views6794
    Read More
  2. [c] 문자열 컨트롤 함수로 만든 프로그램들..

    Date2003.04.23 CategoryDevelop Byhooni Views6786
    Read More
  3. [php] 피코맥스용 검색엔진 ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views6782
    Read More
  4. [c] 파일 복사(copy) 프로그램 샘플 소스

    Date2003.04.23 CategoryDevelop Byhooni Views6772
    Read More
  5. [js] 실행되는 디렉토리 확인하는 스크립트..

    Date2013.04.23 CategoryDevelop Byhooni Views6766
    Read More
  6. [js] 한글문서로 된 259가지 자바스크립트 예제파일

    Date2013.04.23 CategoryDevelop Byhooni Views6765
    Read More
  7. [c] 시간 계산 하는 프로그램 소스코드

    Date2003.04.23 CategoryDevelop Byhooni Views6746
    Read More
  8. [c] 프로그래밍 과제..(colprint)

    Date2003.04.23 CategoryDevelop Byhooni Views6745
    Read More
  9. [pdf] C 국제 표준 문서

    Date2013.04.23 CategoryDevelop Byhooni Views6743
    Read More
  10. [js] 윈도우 시작버튼처럼 나오는 메뉴

    Date2013.04.23 CategoryDevelop Byhooni Views6743
    Read More
  11. [c] 싱글, 더블 링크리스트(linked list)로 만든 예제..

    Date2003.04.23 CategoryDevelop Byhooni Views6737
    Read More
  12. [c] 소켓주소 구조체에 대해..

    Date2003.04.23 CategoryDevelop Byhooni Views6733
    Read More
Board Pagination Prev 1 ... 64 65 66 67 68 69 70 71 72 73 ... 98 Next
/ 98