第十五周项目1(3)-验证算法(冒泡排序)

1.冒泡排序
#include 
#define MaxSize 20
typedef int KeyType;    //定义关键字类型
typedef char InfoType[10];
typedef struct          //记录类型
{
    KeyType key;        //关键字项
    InfoType data;      //其他数据项,类型为InfoType
} RecType;              //排序的记录类型定义

void BubbleSort(RecType R[],int n)
{
    int i,j,k;
    RecType tmp;
    for (i=0; ii; j--)   //比较,找出本趟最小关键字的记录
            if (R[j].key
2.改进算法(一趟冒泡没有交换,即时结束排序过程
#include 
#define MaxSize 20
typedef int KeyType;    //定义关键字类型
typedef char InfoType[10];
typedef struct          //记录类型
{
    KeyType key;        //关键字项
    InfoType data;      //其他数据项,类型为InfoType
} RecType;              //排序的记录类型定义
void BubbleSort1(RecType R[],int n)
{
    int i,j,k,exchange;
    RecType tmp;
    for (i=0; ii; j--)   //比较,找出最小关键字的记录
            if (R[j].key

你可能感兴趣的:(第十五周项目1(3)-验证算法(冒泡排序))