/************************排序算法********************************************/
#include <iostream>
using namespace std;
void insertSort(int r[],int n);//直接插入
void shellSort(int r[],int n);//shell排序
void selectSort(int r[],int n);//直接选择排序
void bubbleSort(int r[],int n);//冒泡排序
void quickSort(int r[],int low,int high);//快速排序
void main(){
int a[]={28,56,32,66,18,43};
//insertSort(a,6);
//shellSort(a,6);
//selectSort(a,6);
//bubbleSort(a,6);
//quickSort(a,0,5);
for(int i=0;i<6;i++){
cout<<a[i]<<endl;
}
}
void insertSort(int r[],int n){
int i,j,s;
for(i=1;i<n;++i){
s = r[i];
j = i-1;
while(s<r[j]){
r[j+1] = r[j];
--j;
}
r[j+1] = s;
}
}
void shellSort(int r[],int n){
int d,i,j,s;
d = n/2;
while(d>=1){
for(i=d;i<n;++i){
s = r[i];
j = i-d;
while( j>=0 && s<r[j] ){
r[j+d] = r[j];
j = j-d;
}
r[j+d] = s;
}
d = d/2;
}
}
void selectSort(int r[],int n){
int i,j,s;
for(i=0;i<n;++i){
for(j=i+1;j<n;++j){
if( r[j]<r[i] ){
s = r[i];
r[i] = r[j];
r[j] = s;
}
}
}
}
void bubbleSort(int r[],int n){
int i,j,bflag,s;
for(i=0;i<n;++i){
bflag = 0;
for(j = n-1;j>i;--j){
if(r[j-1]>r[j]){
s = r[j-1];
r[j-1] = r[j];
r[j] = s;
bflag = 1;
}
}
if(0 == bflag)
return;
}
}
void quickSort(int r[],int low,int high){
if(low<high){
int pos,s,left,right;
s = r[low];
left = low;
right = high;
while(left<right){
while(left<right && r[right]>=s)
--right;
r[left] = r[right];
while(left<right && r[left]<=s)
++left;
r[right] = r[left];
}
r[left] = s;
pos = left;
if( low<(pos-1) )
quickSort(r,low,pos-1);
if( (pos+1)<high )
quickSort(r,pos+1,high);
}
}