Bubble Sort

#include<stdio.h>

int main(){
int a[]={5,1,4,3,2};
int i,k,m,tmp,len = 5;
for(m=0;m<len;m++)
printf("%d ",a[m]);
printf("\n");

for(i=0;i<len;i++)
for(k=0;k<len-1;k++){

if(a[k]>a[k+1]){

tmp = a[k];
a[k]=a[k+1];
a[k+1]=tmp;
printf("Round %d : Swap [%d,%d] ",i+1,a[k],a[k+1]);
for(m=0;m<len;m++)
printf("%d ",a[m]);
printf("\n");
}
}
for(m=0;m<len;m++)
printf("%d ",a[m]);
return 0;
}

Popular posts from this blog

เทคนิค ชนะ เกมเศรษฐี 14 ตารวด!!! ( Let's get Rich )

Using Google Chrome Inspect Element to Analyze the website

Easy way to download whole youtube play list and convert them to mp3