#include <stdio.h>
void swap(int *a, int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
int partition(int arr[], int low, int high)
{
int pivot=arr[high];
int i=low-1;
for(int j=low; j<high; j++)
{
if(arr[j]<=pivot)
{
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[high], &arr[i+1]);
return(i+1);
}
void quicksort(int arr[], int low, int high)
{
if(low<high)
{
int pi=partition(arr, low, high);
quicksort(arr, low, pi-1);
quicksort(arr,pi+1, high);
}
}
void printarray(int arr[], int size)
{
for(int i=0; i<size; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
void main()
{
int size;
printf("Enter size\n");
scanf("%d", &size);
int arr[size];
printf("Enter array\n");
for(int i=0; i<size; i++)
scanf("%d", &arr[i]);
printf("Before sort :\n");
printarray(arr,size);
quicksort(arr, 0, size-1);
printf("After sort :\n");
printarray(arr, size);
}
To embed this program on your website, copy the following code and paste it into your website's HTML: