Contents

조회 수 2020 댓글 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. [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리

    Date2019.11.22 CategoryDatabase Byhooni Views2623
    Read More
  2. [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories)

    Date2015.01.02 CategorySystem/OS Byhooni Views2623
    Read More
  3. [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback)

    Date2014.11.27 CategorySystem/OS Byhooni Views2606
    Read More
  4. [ios] 스크린 캡쳐 (전원버튼 + 홈버튼) 호출 알아내기

    Date2014.11.19 CategoryDevelop Byhooni Views2595
    Read More
  5. [sh] html 안에 있는 img 다운 받는 쉘 스크립트

    Date2020.05.26 CategoryDevelop Byhooni Views2555
    Read More
  6. [c] FSN 온라인 코딩 테스트 (Sorting, Binary Search)

    Date2015.06.26 CategoryDevelop Byhooni Views2552
    Read More
  7. [mac] Mac OS 패키지 매니저, HomeBrew

    Date2015.01.03 CategorySystem/OS Byhooni Views2545
    Read More
  8. '2014 모바일 개발 트렌드' 발표자료입니다.

    Date2014.10.02 CategoryDevelop Byhooni Views2532
    Read More
  9. [ppt] iOS 플라랩#01(2015.02.26) 발표 자료

    Date2015.02.25 CategoryPPT Byhooni Views2530
    Read More
  10. [ppt] iOS 플라랩#02(2015.03.19) 발표 자료

    Date2015.04.24 CategoryPPT Byhooni Views2529
    Read More
  11. OCB5 Injection 앗싸뵹! ㅋㅋ

    Date2014.07.01 CategoryAlgorithm Byhooni Views2513
    Read More
  12. [c] 파일명 또는 특정 패턴을 적용

    Date2016.08.03 CategoryDevelop Byhooni Views2404
    Read More
Board Pagination Prev 1 ... 86 87 88 89 90 91 92 93 94 95 ... 99 Next
/ 99