Created
July 11, 2018 07:14
-
-
Save syedsouban/230ad57f79b81a90812f9ba4d275d8da to your computer and use it in GitHub Desktop.
This file contains 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
#include<stdio.h> | |
void swap(int* x,int* y) | |
{ | |
int t; | |
t=*x; | |
*x=*y; | |
*y=t; | |
} | |
int partition(int* a,int start,int end) | |
{ | |
int pivot=a[end]; | |
int pIndex=start,i,t; | |
for(i=start;i<end;i++) | |
{ | |
if(a[i]<=pivot) | |
{ | |
swap(&a[i],&a[pIndex]); | |
pIndex++; | |
} | |
} | |
swap(&a[end],&a[pIndex]); | |
return pIndex; | |
} | |
void QuickSort(int *a, int start,int end) | |
{ | |
if(start>=end) return; | |
int pIndex=partition(a,start,end); | |
QuickSort(a,start,pIndex-1); | |
QuickSort(a,pIndex+1,end); | |
} | |
main() | |
{ | |
int n; | |
scanf("%d",&n); | |
int a[n]; | |
for(int i=0;i<n;i++) | |
{ | |
scanf("%d",&a[i]); | |
} | |
QuickSort(a,0,n-1); | |
for(int i=0;i<n;i++) | |
printf("%d ",a[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment