//Microsoft Visual Studio6.0 ANSI C에서 정상적으로 돌아가는 버블정렬 소스입니다
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
#define MAX_SIZE 1000000
int list[MAX_SIZE];
int n;
void bubble_sort();
void main()
{
int i;
clock_t a,b;
printf("Number of Records = ");
scanf("%d",&n);
srand((unsigned)time(NULL));
for(i=0;i<n;i++)
{
list[i] = (rand()*rand())%1000000;
printf("%d ",list[i]);
}
a=clock();
bubble_sort();
b=clock();
printf("\n\nSofted Array :\n");
for(i=0;i<n;i++)
printf("%d ",list[i]);
printf("\n");
printf("Excuteion Duration = %f\n",(double)(b-a)/CLK_TCK);
}
void bubble_sort()
{
int i,j,temp;
for(i=n-1;i>0;i--)
{
for(j=0;j<i;j++)
if(list[j]>list[j+1])
SWAP(list[j],list[j+1],temp);
}
}