//冒泡法排序
void bubbleSort ( int a[] ,int n)
{ //思想是把i所指向的空间都取值为未排序的其他数值中最小的那 //一个
for(int i=0;i<len-1;i++)
for(int j=i+1;i<len;j++)
if(a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
void main()
{
int a[]={7,3,5,9,1,8,2,4,6,0};
bubbleSort(a,10);
}
//教材中给出的冒泡排序算法
void BubbleSort(RecordList L)
{
for(i=1;i<=L.length;i++)
for(j=1;j<=L.length-i;j++)
{
if(L.r[j].key>L.r[j+1].key) { temp=a[j]; a[j]=a[j+1];a[j+1]=temp; }
}
}
//冒泡排序算法的改进版本 对于序列 31 12 42 55 68 90 这样一个序列,进行第一趟排序后该
//序列已经基本有序,无须在进行后面的比较,因此算法可以进行改进
void BubbleSort(RecordList L)
{
int flag=1;
for(i=1;(i<=L.length)&&flag;i++)
{ flag=0;
for(j=1;j<=L.length-i;j++)
{
flag=1;
if(L.r[j].key>L.r[j+1].key) { temp=a[j]; a[j]=a[j+1];a[j+1]=temp; }
}
}
}
//快速排序算法
int QKpass(RecordList L ,int low ,int high)
{
L.r[0]=L.r[low];
while(low<high)
{
while(low<high&&L.r[high]>=L.r[0]) high–;
L.r[low]=L.r[high];
while(low<high&&L.r[low]<L.r[0]) low++;
L.r[high]=L.r[low];
}
return low;
}
void QKsort(RecordList L,int Low,int high)
{
if(low<high)
{
Pos=QKpass(RecordList L,low,high);
QKsort(RecordList L,low,pos-1);
QKsort(RecordList L, pos+1,high);
}
}