#define SIZE 20
void dubble_sort(){
int i,j,n=SIZE,tmp;
int array[SIZE+1]={0,12,42,22,34,23,56,2,15,432,11,11,24,232,566,2,11,56,342,23,7778};
for(i=n;i>=2;i--){
for(j=1;j<i;j++){
if(array[j]>array[j+1])
{
tmp=array[j+1];
array[j+1]=array[j];
array[j]=tmp;
}
}
}
for(j=1;j<=n;j++)
{
printf("%d ",array[j]);
}
printf("\n");
}
int fast_sort(int array[],int low,int high){
int povket=array[low];
while(low<high)
{
while((low<high)&&(array[high]>povket)) --high;
array[low]=array[high];
while((low<high)&&(array[low]<povket)) ++low;
array[high]=array[low];
}
array[low]=povket;
return low;
}
void fast_sort_main(int array[],int low,int high){
int postion;
if(low<high){
postion=fast_sort(array,low,high);
fast_sort_main(array,low,postion-1);
fast_sort_main(array,postion+1,high);
}
}
int main(){
int i;
int array[SIZE+1]={0,12,45,3,23,126,5,333,67,12,6,366,21,6,30,21,11,6,44,32,12};
for(i=1;i<SIZE;i++)
printf(" %d ",array[i]);
printf("\n");
fast_sort_main(array,1,SIZE);
return 0;
}
void dubble_sort(){
int i,j,n=SIZE,tmp;
int array[SIZE+1]={0,12,42,22,34,23,56,2,15,432,11,11,24,232,566,2,11,56,342,23,7778};
for(i=n;i>=2;i--){
for(j=1;j<i;j++){
if(array[j]>array[j+1])
{
tmp=array[j+1];
array[j+1]=array[j];
array[j]=tmp;
}
}
}
for(j=1;j<=n;j++)
{
printf("%d ",array[j]);
}
printf("\n");
}
int fast_sort(int array[],int low,int high){
int povket=array[low];
while(low<high)
{
while((low<high)&&(array[high]>povket)) --high;
array[low]=array[high];
while((low<high)&&(array[low]<povket)) ++low;
array[high]=array[low];
}
array[low]=povket;
return low;
}
void fast_sort_main(int array[],int low,int high){
int postion;
if(low<high){
postion=fast_sort(array,low,high);
fast_sort_main(array,low,postion-1);
fast_sort_main(array,postion+1,high);
}
}
int main(){
int i;
int array[SIZE+1]={0,12,45,3,23,126,5,333,67,12,6,366,21,6,30,21,11,6,44,32,12};
for(i=1;i<SIZE;i++)
printf(" %d ",array[i]);
printf("\n");
fast_sort_main(array,1,SIZE);
return 0;
}