BubbleSort

来源:互联网 发布:花生壳 免费 域名 流量 编辑:程序博客网 时间:2024/06/08 23:33
#include<stdio.h>
#define MAXE 20
typedef int KeyType;
typedef char InfoType[10];
typedef struct{
        KeyType key;
InfoType data;
}RecType;
void BubblePass(RecType R[],int n){
     int i,j,k;
RecType w;
     for(i=0;i<n-1;i++)
{
for(j=n-1;j>i;j--)
{
if(R[j].key<R[j-1].key)
{
 w=R[j];
 R[j]=R[j-1];
 R[j-1]=w;
}
 }
printf("冒泡结果为:");
 for(k=0;k<n;k++)
 printf("%3d",R[k].key);
 printf("\n");
}
}
0 0
原创粉丝点击