Quick Sort
/* Quick Sort taking first element as pivot element*/
#include<stdio.h>
#include<stdlib.h>
void QuickSort(int*,int ,int );
int main()
{
int i,j,n,m,*arr;
printf("enter the amount of number to be sort\n");
scanf("%d",&n);
printf("enter the values to be sort\n");
arr=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
QuickSort(arr,0,n-1);
for(i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
system("\n pause");
return 0;
}
void QuickSort(int* arr,int start,int last)
{
int i=start+1,j=last,temp;
if(i>j)
return;
while(i<=j)
{
if(arr[i]<arr[start])
{
i++;
}
if(arr[j]>arr[start])
{
j--;
}
if(i<=j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
temp=arr[start];
arr[start]=arr[j];
arr[j]=temp;
QuickSort(arr,start,j-1);
QuickSort(arr,j+1,last);
}