'정렬'에 해당되는 글 1건

  1. 2008/05/16   정렬 알고리즘 - 거품정렬(bubble sort) (2)

버블정렬.
저음엔 이거만 있는 줄 알았는데.
지금은 GG상태.


Z F A N T A
F Z A N T A
F A Z N T A
F A N Z T A
F A N T Z A
... ... ... ... ... ...

이런 식으로 비고하면서 정렬된다.
몇 번 더해야되.
#include <stdlib.h>  
#include <stdio.h>   
#include <time.h>   
#include <conio.h> 

int main()   
{   
    int a[100];   
    int start,end;   
    int max,min;   
    int count,count2;   
    int temp; 

    srand((unsigned)time(NULL));   

    printf("시작 : ");   
    scanf("%d",&start);   
    printf("종료 : ");   
    scanf("%d",&end);   

    min=end;   
    max=start;   

    printf("정렬 전\n"); 
    for(count=0;count<20;count++)   
    {   
        a[count]=rand() % (end - start + 1) + start;               
        printf("%3d",a[count]);   
    } 

    /*여기부터*/
    for (count = 20-1; count > 0 ; count--)
    {
        for (count2 = 1; count2 <= count ; count2++)
        {
            if (a[count2-1] > a[count2])
            {
                temp = a[count2-1];
                a[count2-1] = a[count2];
                a[count2] = temp;      
            }
        }
    }
    /*여기까지 거품정렬입니다.*/

    printf("\n정렬 후\n"); 
    for(count=0;count<20;count++)   
    {   
        printf("%3d",a[count]);   
    } 

    getch(); 
    return 0;   
}


참고 : 선택정렬


이거 좀 날로 먹는듯 ㅋㅋㅋ

이 글이 유익하다면 (굽신굽신) ->

Trackback Address >> http://zfanta.com/trackback/377 관련글 쓰기

  1. BlogIcon 혜윰 2008/05/24 20:56  address  modify / delete  reply

    버블소트 == 거품정렬
    가끔..한글로 바꿔 부르면 재밌게 들리는때가 있는거 같아요ㅎㅎ
    웃고가요~