1. 起泡排序
void BubbleSort(int R[],int n)
{
int i,j,flag;
int temp;
for(i=n-1;i>=1;--i)
{
flag = 0;
for(j=1;j<=i;++j)
{
if(R[j-1]>R[j])
{
temp = R[j];
R[j]=R[j-1];
R[j-1]=temp;
flag = 1;
}
}
if(flag == 0) //一趟排序过程中没有发生关键字交换,则证明有序
return;
}
}
2. 快速排序
int Partition(int A[],int low,int high)
{
int pivot = A[low];
while(low<high)
{
while(low<high && A[high] >= pivot)
--high;
A[low] = A[high];
while(low<high && A[low] <= pivot)
++low;
A[high] = A[low];
}
A[low] = pivot;
return low;
}
void QuickSort(int A[],int low,int high)
{
if(low<high)
{
int pivotpos = Partition(A,low,high);
QuickSort(A,low,pivotpos-1);
QuickSort(A,pivotpos+1,high);
}
}
3.双向冒泡排序算法
void BubbleSort(int A[],int n)
{
//双向起泡排序,交替进行正反两个方向的起泡过程
int i,low=0,high=n-1