Bubble sort
#include <stdio.h>
void Bubblesort (int *a,int n);
int main (void)
{
int k;
int a[10]={2,4,6,8,0,1,3,5,7,9};
for (k=0;k<10;k++)
{
if (k==9)
printf ("%d\n", A[k]);
Else
printf ("%d,", a[k]);
}
Bubblesort (a,10);
for (k=0;k<10;k++)
{
if (k==9)
printf ("%d\n", A[k]);
Else
printf ("%d,", a[k]);
}
return 0;
}
void Bubblesort (int *a,int N)
{
int i,j,t;
for (i=0;i<n-1;i++)
for (j=0;j<n-i-1;j++)
{
if (a[j]>a[j+1])
{
T=A[J];
A[J]=A[J+1];
a[j+1]=t;
}
}
}
Select sort
#include <stdio.h>
void Selectsort (int *a,int n);
int main (void)
{
int k;
int x[10]={2,4,6,8,0,1,3,5,7,9};
for (k=0;k<10;k++)
printf ("%d", x[k]);
printf ("\ n");
Selectsort (x,10);
for (k=0;k<10;k++)
printf ("%d", x[k]);
printf ("\ n");
return 0;
}
void Selectsort (int *a,int N)
{
int i,j,t;
int min;
for (i=0;i<n-1;i++)
{
Min=i;
for (j=i+1;j<n;j++)
{
if (A[j]<a[min])
Min=j;
}
T=a[i];
A[i]=a[min];
a[min]=t;
}
}
Okay, the above is the cloud Habitat Community small partners for you to organize an example of the C language sorting method, I hope that these two algorithms can be helpful to you beginners.