/*冒泡排序算法是把大的元素向上移(气泡的上浮),也可以把小的元素向下移(气泡的下沉)*/
/*请给出上浮和下沉过程交替的冒泡排序算法*/
#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
上浮和下沉过程交替的冒泡排序算法
最新推荐文章于 2022-10-25 18:11:36 发布
本文详细探讨了一种独特的冒泡排序算法,该算法通过交替进行上浮和下沉过程来优化排序效率。这种方法旨在减少不必要的比较和交换操作,提高排序速度。通过对数组元素的巧妙操作,实现了更高效的冒泡排序过程。
摘要由CSDN通过智能技术生成