#include <stdio.h>
Bubble sort
void Maopao (int arr[],int len) {
for (int i=0;i<len-1;i++) {
for (int j=0;j<len-i-1;j++) {
if (Arr[j] > arr[j+1]) {
int temp = Arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
}
}
}
}
Select sort
void Selectsort (int arr[],int len) {
int temp;
for (int i=0;i<len-1;i++) {
for (int j=i+1;j<len;j++) {
if (Arr[i] > Arr[j]) {
temp = Arr[i];
Arr[i] = Arr[j];
ARR[J] = temp;
}
}
}
}
The binary algorithm is also called a binary lookup algorithm
int twosort (int * Listdata,int listlength)
{
int i = 0;
int j = 0;
for (i=1;i<=listlength;i++)
{
Int TMP = Listdata[i];
int low = 0;
int hight = i-1;
int mid;
while (Low <= hight)
{
Mid = (low+hight)/2;
if (tmp > Listdata[mid])
low = mid+1;
Else
Hight = mid-1;
}
for (j=i-1;j>=low;j--)
LISTDATA[J+1]=LISTDATA[J];
listdata[low]=tmp;
}
return 0;
}
int main () {
int a[9] = {1,3,5,7,6,8,9,2,4};
printf ("\ n bubble sort source data \ n");
for (int g=0;g<9;g++) {
printf ("%d\t", A[g]);
}
Maopao (a,9);
printf ("\ n bubble sorted data \ n");
for (int i=0;i<9;i++)
printf ("%d\t", A[i]);
int b[9] = {1,3,5,7,6,8,9,2,4};
printf ("\ n Select sort source data \ n");
for (int g=0;g<9;g++) {
printf ("%d\t", B[g]);
}
Selectsort (b,9);
printf ("\ n select sorted data \ n");
for (int i=0;i<9;i++)
printf ("%d\t", B[i]);
int c[9] = {1,3,5,7,6,8,9,2,4};
printf ("\ n binary algorithm source data \ n");
for (int g=0;g<9;g++) {
printf ("%d\t", C[g]);
}
Twosort (c,9);
printf ("\ n binary algorithm after data \ n");
for (int i=0;i<9;i++)
printf ("%d\t", C[i]);
return 0;
}
Several algorithms commonly used in C language