diff --git a/Cpp/QuickSort.cpp b/Cpp/QuickSort.cpp new file mode 100644 index 0000000..6dcbacb --- /dev/null +++ b/Cpp/QuickSort.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +//Quick Sort Implemented in C++ + +int partition(int a[],int s,int e){ + int i=s; + int pivot = a[e]; + for(int j=s;j<=e-1;j++){ + if(a[j] < pivot){ + swap(a[i],a[j]); + i++; + } + } + swap(a[i],a[e]); + return i; +} + +void quickSort(int a[],int s,int e){ + if(s>=e){ + return; + } + int p = partition(a,s,e); + quickSort(a,s,p-1); + quickSort(a,p+1,e); +} + +int main(){ + int n; + cin>>n; + int a[n]; + for(int i=0;i>a[i]; + } + quickSort(a,0,n-1); + for(int i=0;i