Monday, January 24, 2011

Code : Sort array style bubbles (EX - 2)

//  Sort array style bubbles (sắp xếp mảng theo kiểu nổi bọt)

  • This arrangement is highly classics.
  • Easy to learn and do.
  • speed is not optimal.
  • Ideas: Light (small) rise in heavy (large) clusters below.



#include<stdio.h>
#include<conio.h>
#define max 5
#include<alloc.h>
void main()
{
 int str[10];
   int i,j,temp;
   printf("\n nhap vao 10phan tu cua mang can sap xep:\n");
   for(i=0;i<10;i++)
   {
    printf("\n a[%d]=",i);
      scanf("%d",&str[i]);
   }
   for(i=1;i<10;i++)
      for(j=0;j<9;j++)
         if(str[j]>str[j+1])
         {
            temp=str[j];
            str[j]=str[j+1];
            str[j+1]=temp;
         }
   for(i=0;i<10;i++)
    printf(" a[%d]=%d",i,str[i]);
getch();
}

No comments:

Post a Comment

Popular Posts