上浮和下沉过程交替的冒泡排序算法

  • Post author:
  • Post category:其他


/*冒泡排序算法是把大的元素向上移(气泡的上浮),也可以把小的元素向下移(气泡的下沉)*/
/*请给出上浮和下沉过程交替的冒泡排序算法*/
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
typedef int KeyType;
typedef int InfoType;

typedef struct
{
    KeyType key;
    InfoType otherinfo;
}RedType;

typedef struct
{
    RedType r[MAXSIZE+1];
    int length;
}SqList;
int LT(KeyType a,KeyType b);
void Bubble_up_Sort(SqList*L);
void Bubble_down_Sort(SqList*L);
void Bubble_Alternative_Sort(SqList *L);

int main()
{
    SqList *L,*L1,*L2;
    L=(SqList *)malloc(sizeof(SqList));
    L1=(SqList *)malloc(sizeof(SqList));
    L2=(SqList *)malloc(sizeof(SqList));

    int i;
    printf("需排序的项数为:");
    scanf("%d",&L->length);

    for(i=0;i<L->length;i++)
    {
        printf("please input the number:");
        scanf("%d",&L->r[i+1].key);
    }
    *L1=*L2=*L;

    Bubble_up_Sort(L1);
    Bubble_dow



版权声明:本文为weixin_43213382原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。