起泡排序

来源:互联网 发布:微信cdn 阿里云cdn 编辑:程序博客网 时间:2024/04/17 04:38
#include <stdio.h>#include <stdlib.h>#define MAXSIZE 20typedef int Keytype;#define TRUE 1#define FALSE 0typedef  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                                                  


原创粉丝点击