#include<stdio.h>
void Bubble_sort(int a[],int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int SelectMinKey(int a[],int n,int i)
{
int k=i,j;
for(j=i+1;j<n;++j)
{
if(a[k]>a[j]) k=j;
}
return k;
}
void selectSort(int a[], int n)
{
int key,tmp,i;
for(i=0;i<n;++i)
{
key=SelectMinKey(a,n,i);
if(key!=i)
{
tmp=a[i];
a[i]=a[key];
a[key]=tmp;
}
}
}
void InsertSort(int a[],int n)
{
int i;
for(i=1;i<n;i++)
{
if(a[i]<a[i-1])
{
int j=i-1;
int x=a[i];
a[i]=a[i-1];
while(x<a[j])
{
a[j+1]=a[j];
j--;
}
a[j+1]=x;
}
}
}
void swap(int *a,int *b)
{
int tmp=*a;
*a=*b;
*b=tmp;
}
int partition(int a[],int low,int high)
{
int privotKey=a[low];
while(low<high)
{
while(low<high && a[high]>=privotKey) --high;
swap(&a[low],&a[high]);
while(low<high && a[low]<=privotKey)++low;
swap(&a[low],&a[high]);
}
return low;
}
void quickSort(int a[],int low,int high)
{
int privotLoc;
if(low<high)
{
privotLoc=partition(a,low,high);
quickSort(a,low,privotLoc-1);
quickSort(a,privotLoc+1,high);
}
}
void print(int a[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%3d",a[i]);
}
int main()
{
int a[8]={49,38,65,97,76,13,27,49};
print(a,8);
printf("\n");
quickSort(a,0,7);
}