//quicksort.c@standard c library(*SCL*) by ASHISH TIWARI
/*
You may print, store code from this program for your personal,
noncommercial use. By accessing this code, you agree not to reproduce,
distribute,
display or transmit information from this code in any form or by any means
without
the permission of ASHISH TIWARI, with this exception: You may occasionally
reproduce,
distribute, display or transmit an insubstantial portion of the information, for
a
noncommercial purpose, to a limited number of individuals. ASHISH TIWARI does
not warrant
the accuracy, completeness, timeliness, merchantability or fitness for a
particular purpose
of the cose,though every care has been taken in making this code and has been
compiled
on standard gcc compiler provided by GNU. ASHISH TIWARI shall not be liable for
any
errors or omissions in the information or decisions made or actions taken in
reliance
on the code.
"*SCL*" is a registered trademark of ASHISH TIWARI, IITKGP.
All contents of "*SCL*" is copyright ©2000-.... ,ASHISH TIWARI, IITKGP
unless otherwise noted. Reproduction in part or in whole without
permission is expressly prohibited.
*/
#include<stdio.h>
void quicksort(int arr[],int start,int end);
int partition(int arr[],int start,int end);
void swap(int *p,int *q);
main()
{
int arr[15];
int i;
for(i=0;i<=14;i++)
scanf("%d",&arr[i]);
quicksort(arr,0,14);
printf("sorted list=>");
for(i=0;i<=14;i++)
printf("%d ",arr[i]);
}
void quicksort(int arr[],int start,int end)
{
int intermediate;
if(start>=end)
return;
else
{
intermediate=partition(arr,start,end);
quicksort(arr,start,intermediate);
quicksort(arr,intermediate+1,end);
}
}
int partition(int arr[],int start,int end)
{
int pivot;
int left,right,temp;
pivot=arr[start];
left=start;
right=end;
while(left<right)
{
while(arr[left]<=pivot)
left++;
while(arr[right]>=pivot)
right--;
if(left<right)
{
temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
}
/*swap(&arr[left],&arr[right]);*/
else
return(right);
}
}
/*void swap(int *p,int *q)
{
int *temp;
*temp=*p;
*p=*q;
*q=*temp;
}
*/