标签:span define size ble ++ std nbsp rtl stdio.h
#include "stdio.h" #define MAXSIZE 20 typedef int ElemType; typedef struct { ElemType r[MAXSIZE+1]; int length; }SortList; /* 冒泡排序:BubbleSort */ void BubbleSort(SortList *L) { int i,j;ElemType t; for(i=1;i<L->length;i++) //排序趟数 for(j=1;j<=L->length-i;j++) //每趟比较的次数 if(L->r[j]>L->r[j+1]) { t = L->r[j]; L->r[j] = L->r[j+1]; L->r[j+1] = t; } } //改进算法 void BubbleSort(SortList *L) { int i,j; ElemType t; int flag = 1; for(i=1;flag&&i<L->length;i++) for(flag=0,j=1;j<=L->length-i;j++) if(L->r[j]>L->r[j+1]) { t = L->r[j]; L->r[j] = L->r[j+1]; L->r[j+1] = t; flag = 1; //有交换,则置交换标记为真,需要进行下趟排序 } } //快速排序 void HoareSort(SortList *L,int low,int high) { int i,j; if(low<high) { i = low; j = high; L->r[0] = L->r[i]; while(i<j) { while(i<j&&L->r[j]>=L->r[0])j--; L->r[i] = L->r[j]; while(i<j&&L->r[i]<L->r[0])i++; L->r[j]=L->r[i]; } L->r[i]=L->r[0]; HoareSort(L,low,i-1); HoareSort(L,i+1,high); } } void QuickSort(SortList *L) { HoareSort(L,1,L->length); }
标签:span define size ble ++ std nbsp rtl stdio.h
原文地址:https://www.cnblogs.com/wzqstudy/p/10213175.html