2018.05.17 21:27

내가 만든 merge sort

조회 수 370 추천 수 0 댓글 3
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form

void merge(int low,int mid,int high,int a[])
{
    int l1=low,l2=mid+1,i,j,b[max+1]={},end=0;
 
    printf("\nmerge start\nl1 = %d l2 = %d low = %d mid = %d high = %d\n",l1,l2,low,mid,high);
 
    for(i=low;end==0;i++) ///confused
    {
        printf("\nrunning for\ni = %d l1 = %d l2 = %d low = %d mid = %d high = %d\nb = ",i,l1,l2,low,mid,high);
 
        if(a[l1]>=a[l2])
            b[i]=a[l2++];
        else
            b[i]=a[l1++];
 
        end!=(l1<=mid)&&(l2<=high);
        //if(l1==l2)
        //    b[max]=a[l1];
 
        for(j=0;j<max+1;j++)
            printf("%d ",b[j]);
        printf("\na = ");
        for(j=0;j<max+1;j++)
            printf("%d ",a[j]);
        printf("\n    ");
 
        for(j=0;j<low*2;j++)
            printf(" ");
        printf("^");
        for(j=low*2;j<high*2-1;j++)
            printf(" ");
        printf("^\n");/**/
    }
 
 
 
    while(l1<=mid)
        b[i++]=a[l1++];
    while(l2<=high)
        b[i++]=a[l1++];
    printf("1\n");
    for(i=low;i<=high;i++)
        a[i]=b[i];
 
    printf("\nending merge\na = ");
    for(i=0;i<max+1;i++)
            printf("%d ",a[i]);
            printf("\n");/**/
}
 
void sort(int low,int high,int a[])
{
    if(low<high)
    {
        int mid=(low+high)/2;
        sort(low,mid,a);
        sort(mid+1,high,a);
        merge(low,mid,high,a);
    }
    else
        return;
}


아...... 힘들었다

  • profile

    #include<stdio.h>가 빠졌는데, 혹시 #으로 시작하는 문장을 사용할 때 자동으로 해시태그가 붙는 문제 때문에 사용하지 않으신 건가요? 그리고 어떤 IDE를 사용하시는 지는 모르겠지만, Dev-C++에서 컴파일하니 오류가 꽤 발생하네요... 죄송하지만 제가 C 왕초보라서 저도 이게 무슨 오류인지 모르겠어요 ㅠㅠ 변수가 정의되지 않은 것 같긴 한데요...



  • profile
    네모 2018.05.18 22:32

    max 변수가 없어서 b 변수도 선언이 안되거 같네요.
    테스트는 안해봤지만....
     
    int l1=low,l2=mid+1,i,j,b[max+1]={},end=0;
    int l1=low,l2=mid+1,i,j,b[high-low+1]={},end=0; 로!

  • ?
    title: 대한민국 국기gimmepoint 2018.05.22 21:19
    저는 함수만 써 놨습니다
    CODE BLOCKS 씁니다

  1. 잘못 쓰면 컴퓨터가 날아가는 코드

    Date2018.07.08 Category코드 By제르엘 Views964
    Read More
  2. 매우 특이한 버그

    Date2018.06.05 Category코드 Bytitle: 대한민국 국기gimmepoint Views569
    Read More
  3. 내가 만든 merge sort

    Date2018.05.17 Bytitle: 대한민국 국기gimmepoint Views370
    Read More
  4. 내가 만든 함수 모음집 2

    Date2018.05.12 Category코드 Bytitle: 대한민국 국기gimmepoint Views379
    Read More
  5. 내가 만든 사칙연산 계산기

    Date2018.05.11 Category코드 Bytitle: 대한민국 국기gimmepoint Views515
    Read More
  6. 내가 만든 함수 모음집

    Date2018.05.08 Category코드 Bytitle: 대한민국 국기gimmepoint Views382
    Read More
  7. 클라이언트단에서 이미지 리사이징

    Date2018.05.06 Category코드 By네모 Views1078
    Read More
  8. HEX를 RGB로, RGB를 HEX로 바꾸는 PHP 코드

    Date2018.05.05 Category코드 By네모 Views507
    Read More
  9. c 이진트리 전,중,후위 알고리즘

    Date2018.04.24 Category코드 Bytitle: 대한민국 국기gimmepoint Views495
    Read More
  10. html 초보가 만든 자소서

    Date2018.04.21 Category코드 Bytitle: 대한민국 국기gimmepoint Views652
    Read More
  11. Hello, World!를 출력해보자

    Date2018.04.21 Category코드 By네모 Views568
    Read More
  12. 아주 간단한 기초 C++

    Date2018.04.21 Category코드 By제르엘 Views477
    Read More
  13. 미완성 받아쓰기 (C)

    Date2018.04.20 Category코드 Bytitle: 대한민국 국기gimmepoint Views380
    Read More
  14. Cmd 에서 서비스 시작 / 종료하기

    Date2018.02.18 Category코드 ByProjectSE Views644
    Read More
  15. CMD로 로컬 연결 고정 IP 설정하기

    Date2018.02.06 Category코드 Bytitle: 황금 서버 (30일)humit Views1038
    Read More
  16. 컴퓨터의 uuid 얻기

    Date2018.01.28 Category코드 Bytitle: 황금 서버 (30일)humit Views1099
    Read More
  17. 유튜브에 약간의 기능을 추가 해주는 크롬 확장 프로그램.

    Date2018.01.26 Category코드 ByHanam09 Views942
    Read More
  18. 사이트 서버 이전 (또는 미러링 사이트 구축) 쉽게하는 스크립트

    Date2018.01.14 Category코드 ByNoYeah Views858
    Read More
  19. 새 글 자동 댓글 스크립트 (AutoHotkey)

    Date2017.11.26 Category코드 By이니스프리 Views3458
    Read More
  20. 파이썬을 이용한 텔레그램 새 글 알림 (허접합니다)

    Date2017.11.19 Category코드 By이니스프리 Views2377
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4