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

  1. 2007.09.03 버블정렬

버블정렬

카테고리 없음 2007. 9. 3. 14:08
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

//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);
     
   
   }
 

  }

Posted by shunman
,