Bubble sort is a sort of contact in high school, simpler and easier to understand relative to other sorts
The feature of this series of blogs is--give the results of each order
Originally wanted to write a good process, get a picture of what, but think online analysis too much, are better, so these blog even if it is a summary of their own it.
#include <stdio.h> void bubblesort (int *m, int n) { int i,j; for (i=0;i<n-1;i++) {for (j=1;j<n-i;j++) if (m[j]<m[j-1]) { m[j]=m[j]^m[j-1]; M[J-1]=M[J]^M[J-1]; M[J]=M[J]^M[J-1]; } for (int t=0;t<10;t++) printf ("%d", m[t]); printf ("\ n");} } int main () { int i; int a[10]={2,8,5,7,4,3,1,9,6,10}; for (i=0;i<10;i++) printf ("%d", A[i]); printf ("\ n" \ n "); Bubblesort (a,10); for (i=0;i<10;i++) printf ("%d", A[i]); printf ("\ n"); return 0;}
after running
Here's an improvement to the sort.
void Bubblesort (int *m, int n) { int i,j; BOOL Flag; for (i=0;i<n-1;i++) { flag=true; for (j=1;j<n-i;j++) if (m[j]<m[j-1]) { m[j]=m[j]^m[j-1]; M[J-1]=M[J]^M[J-1]; M[J]=M[J]^M[J-1]; Flag=false; } for (int t=0;t<10;t++) printf ("%d", m[t]); printf ("\ n"); if (flag) break ; }}
after running
Sorting algorithm Big Collection _ Exchange Class--bubble sort