From dfad2ee332dcd2e10a1ef107aed81a4dd867fac7 Mon Sep 17 00:00:00 2001 From: Roshan Prakash Raut Date: Thu, 1 Oct 2020 17:08:53 +0530 Subject: [PATCH 1/2] Added Quick sort algorithm in C++ . --- Sorting/quick_sort/quick_sort.cpp.cpp | 96 +++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Sorting/quick_sort/quick_sort.cpp.cpp diff --git a/Sorting/quick_sort/quick_sort.cpp.cpp b/Sorting/quick_sort/quick_sort.cpp.cpp new file mode 100644 index 0000000..fb1e99d --- /dev/null +++ b/Sorting/quick_sort/quick_sort.cpp.cpp @@ -0,0 +1,96 @@ +/* +QUICK SORT ALGORITHM : TIME COMPLEXITY O(nlogn(n)) + +*/ + + +#include +using namespace std; + +//note: call by address in swap function +void swap(int *a,int *b) +{ + int t; + t=*a; + *a=*b; + *b=t; +} + + +//partition function which makes partition in array and return the partition index +int partition(int a[],int low ,int high) +{ + // i is leftmost index and j is the rightmost index + int i = low,j = high; + int pivot = a[low]; + + + do{ + do + { + i++; + }while(a[i]<=pivot); //note :condition is for continuation of loop ans not for stop + + do + { + j--; + }while(a[j]>pivot); // note: condition is for continuation of loop and not for stop + + + if(i Date: Sat, 3 Oct 2020 01:04:12 +0530 Subject: [PATCH 2/2] Custom array input added and file name corrected --- Sorting/bucket_sort/quick_sort.cpp | 106 ++++++++++++++++++ .../{quick_sort.cpp.cpp => quick_sort.cpp} | 14 ++- 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 Sorting/bucket_sort/quick_sort.cpp rename Sorting/quick_sort/{quick_sort.cpp.cpp => quick_sort.cpp} (92%) diff --git a/Sorting/bucket_sort/quick_sort.cpp b/Sorting/bucket_sort/quick_sort.cpp new file mode 100644 index 0000000..7febd93 --- /dev/null +++ b/Sorting/bucket_sort/quick_sort.cpp @@ -0,0 +1,106 @@ +/* +QUICK SORT ALGORITHM : TIME COMPLEXITY O(nlogn(n)) + +*/ + + +#include +using namespace std; + +//note: call by address in swap function +void swap(int *a,int *b) +{ + int t; + t=*a; + *a=*b; + *b=t; +} + + +//partition function which makes partition in array and return the partition index +int partition(int a[],int low ,int high) +{ + // i is leftmost index and j is the rightmost index + int i = low,j = high; + int pivot = a[low]; + + + do{ + do + { + i++; + }while(a[i]<=pivot); //note :condition is for continuation of loop ans not for stop + + do + { + j--; + }while(a[j]>pivot); // note: condition is for continuation of loop and not for stop + + + if(i>n; + + int arr[n]; + + //input the custom array + for(int i=0;i>arr[i]; + } + + + cout<<"Before Quick Sort array is : "; + for(int i=0;i>n; + + int arr[n]; + + //input the custom array + for(int i=0;i>arr[i]; + } + cout<<"Before Quick Sort array is : "; for(int i=0;i