#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
typedef int Keytype;
#define TRUE 1
#define FALSE 0
typedef struct{
Keytype key;
//InfoType otherinfo;
}RedType;
typedef struct{
RedType r[MAXSIZE+1];
int length;
}SqList;
void bubble_sort(int a[], int n);
int main(void){
int i;
int ls[] ={7,6,5,4,3,2,1};
bubble_sort(ls, 7);
for(i=0; i<7; i++)
printf(" %d ",ls[i]);
putchar('\n');
return 0;
}
void bubble_sort(int a[], int n){
int i, j, change, tmp;
for(i=n-1, change=TRUE; i>=1 && change; --i){
change=FALSE;
for(j=0; j<i; ++j)
if(a[j] > a[j+1]){
tmp = a[j];
a[j]=a[j+1];
a[j+1]=tmp;
change=TRUE;
}
}
}// bubble_sort
起泡排序
最新推荐文章于 2021-07-28 00:53:53 发布