//Minh hoa thuat BubbleSort (sap xep noi bot) #include<stdio.h> #include<conio.h> int Mang[10]={10,9,8,7,6,5,4,3,2,1}; // ham in day so trong mang voi n phan tu void inday(int mang[],int n) { int vtin; for(vtin=0;vtin<n;vtin++) printf("%d ",mang[vtin]); } void BubbleSort(int mang[],int n) { int i,j,xtam; for(i=0;i<n;i++) for(j=n-1;j>i;j--) if(mang[j]<mang[j-1]) //neu mang[j]>mang[j-1] thi doi cho { xtam=mang[j]; mang[j]=mang[j-1]; mang[j-1]=xtam; } } void main() { clrscr(); printf("Day so truoc khi sap xep la\n"); inday(Mang,10); printf("\nDay so sau khi sap xep la\n"); BubbleSort(Mang,10); inday(Mang,10); getch(); }
nosomovo