Skip to content

Commit 7315e9f

Browse files
committed
Quick sort with pivort low index implemented
1 parent 24fa84e commit 7315e9f

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Sorting Algorithm/QuickSort1.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int getPivort(int arr[],int low, int high){
6+
int i = low;
7+
int j = high;
8+
int pivort = arr[low];
9+
10+
while(i<j){
11+
while(arr[i]<=pivort && i<high) i++;
12+
while(arr[j]>pivort && j>=low) j--;
13+
if(i<j) swap(arr[i],arr[j]);
14+
}
15+
swap(arr[j],arr[low]);
16+
return j;
17+
}
18+
19+
void quickSort(int arr[], int low,int high){
20+
if(high>low){
21+
int pivort = getPivort(arr,low,high);
22+
quickSort(arr,low,pivort-1);
23+
quickSort(arr,pivort+1,high);
24+
cout<<"Hi"<<endl;
25+
}
26+
}
27+
28+
void printArr(int arr[],int n){
29+
for(int i=0; i<n; i++){
30+
cout<<arr[i]<<" ";
31+
}
32+
}
33+
34+
int main(){
35+
// freopen("input.txt","r",stdin);
36+
int n;
37+
cin>>n;
38+
int arr[n];
39+
for(int i=0; i<n; i++){
40+
cin>>arr[i];
41+
}
42+
43+
quickSort(arr,0,n-1);
44+
printArr(arr,n);
45+
}

0 commit comments

Comments
 (0)