Last active
August 29, 2015 14:01
-
-
Save zsrinivas/5f9820a6c1d184b19d14 to your computer and use it in GitHub Desktop.
A lame implementaion of Quick Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Test Program*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#include <assert.h> | |
#include <ctype.h> | |
#include "quicksort.h" | |
#define MAXSIZ 100000 | |
int main(int argc, char const *argv[]) | |
{ | |
long long int a[MAXSIZ]; | |
long long int n,i; | |
scanf("%lld", &n); | |
for (i = 0; i < n; ++i) | |
scanf("%lld", &a[i]); | |
quicksort(a,0,n-1); | |
for (i = 0; i < n; ++i) | |
printf("%lld\n", a[i]); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Header File for the Quick Sort*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#include <assert.h> | |
#include <ctype.h> | |
int quicksort(long long int unsortedarray[], long long int low, long long int high) | |
{ | |
long long int pivot=unsortedarray[low]; | |
long long int k,temp,i; | |
if (low<high) | |
{ | |
k=low+1; | |
for (i = low+1; i <= high; ++i) | |
{ | |
if (unsortedarray[i]<pivot) | |
{ | |
temp=unsortedarray[i]; | |
unsortedarray[i]=unsortedarray[k]; | |
unsortedarray[k++]=temp; | |
} | |
} | |
temp=unsortedarray[low]; | |
unsortedarray[low]=unsortedarray[--k]; | |
unsortedarray[k]=temp; | |
quicksort(unsortedarray,low,k-1); | |
quicksort(unsortedarray,k+1,high); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment