Contents

조회 수 922 댓글 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. [c] 격자 직사각형 넓이 구하기

    Date2013.04.23 CategoryDevelop Byhooni Views7466
    Read More
  2. [c] 공용체를 이용해 MSB를 LSB로 변환

    Date2013.04.23 CategoryDevelop Byhooni Views9386
    Read More
  3. [c] 관계형 연산자에 대한 설명

    Date2013.04.23 CategoryDevelop Byhooni Views7672
    Read More
  4. [c] 구구단 최단라인 ㅡㅡ;

    Date2013.04.23 CategoryDevelop Byhooni Views8023
    Read More
  5. [c] 구조체 배열 예제 (학생 성적 계산)

    Date2013.04.23 CategoryDevelop Byhooni Views7674
    Read More
  6. [c] 구조체/파일 입출력 프로그램

    Date2003.04.23 CategoryDevelop Byhooni Views7076
    Read More
  7. [c] 구조체의 설명과 예제..

    Date2003.04.23 CategoryDevelop Byhooni Views8386
    Read More
  8. [c] 그래픽 차트 라이브러리.. 나중에 확인 해볼 거..

    Date2013.04.23 CategoryDevelop Byhooni Views8230
    Read More
  9. [c] 그래픽스 자료(OpenGL 라이브러리) 샘플 소스

    Date2003.04.23 CategoryDevelop Byhooni Views10199
    Read More
  10. [c] 근의 공식으로 2차방정식 풀기..

    Date2003.04.23 CategoryDevelop Byhooni Views7791
    Read More
  11. [c] 기막힌 정렬 코드 ㅋㄷ

    Date2015.10.13 CategoryDevelop Byhooni Views920
    Read More
  12. [c] 기본 자료형(int)이 표현할 수 없는 큰 수(Big number)를 덧셈하는 코드.

    Date2013.04.23 CategoryDevelop Byhooni Views13467
    Read More
Board Pagination Prev 1 ... 18 19 20 21 22 23 24 25 26 27 ... 98 Next
/ 98