#include <stdio.h>
#define MAX_SIZE 6
#define SWAP(x, y, t) ( (t)=(x), (x)=(y), (y)=(t) )

int list[MAX_SIZE]={ 1, 2, 4, 3, 5, 6};
int n, sw=0, count=0;

void bubble_sort(int list[], int n)
{
        int i, j, temp;
        for(i=n-1; i>0; i--) {
                for(j=0; j<i; j++)
                        if(list[j] > list[j+1])
                        {
                                sw=1;                              // 여기 sw=1 설정
                                SWAP(list[j], list[j+1], temp);
                        }
                        if(sw==0)                                // sw=0라고 했는데 어떻게 해서 0으로 변하게 되나요???????????????
                                break;
                        sw=0;
                        count++;
        }
}

void main()
{
        int i;
        n = MAX_SIZE;

        bubble_sort(list, n);
        printf("비교횟수: %d \n", count);
        for(i=0; i<n; i++)
                printf("%d ", list[i]);
        printf("\n");
}