Skip to content

Instantly share code, notes, and snippets.

@RakibOFC
Created October 13, 2020 02:57
Show Gist options
  • Save RakibOFC/714088ff25c2a98807dcef8385e5d628 to your computer and use it in GitHub Desktop.
Save RakibOFC/714088ff25c2a98807dcef8385e5d628 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int quicksort(int a[], int first, int last)
{
int i, j, pivot, temp;
if(first < last)
{
pivot = first;
i = first;
j = last;
while(i < j)
{
while(a[i] <= a[pivot] && i < last)
{
i++;
}
while(a[j] > a[pivot])
{
j--;
}
if(i < j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
temp = a[pivot];
a[pivot] = a[j];
a[j] = temp;
quicksort(a, first, j-1);
quicksort(a, j+1, last);
}
}
int main()
{
int i, num, a[270000];
double start, end;
srand(time(0));
printf("Enter input size: ");
scanf("%d", &num);
printf("\nInput Array: ");
for(i = 0; i < num; i++)
{
a[i] = rand()%1000;
printf("%d ", a[i]);
}
start = clock();
quicksort(a, 0, num-1);
end = clock();
printf("\nAfter sort: ");
for(int i = 0; i < num; i++)
{
printf("%d ", a[i]);
}
printf("\n\nExecution time: %.3lf s\n\n", (end-start)/1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment