-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3assignment.cpp
More file actions
49 lines (47 loc) · 1.01 KB
/
Copy path3assignment.cpp
File metadata and controls
49 lines (47 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;
void swap(int arr[], int pos1, int pos2){
int temp;
temp=arr[pos1];
arr[pos1]=arr[pos2];
arr[pos2]=temp;
}
int partition(int arr[], int low, int high, int pivot ){
int a=low;
int b=low;
while(a<=high){
if(arr[a]>pivot){
a++;
}
else{
swap(arr, a, b);
a++;
b++;
}
}
return b-1;
}
void quicksort(int arr[], int low, int high){
if (low < high){
int pivot=arr[high];
int pos= partition(arr, low, high, pivot);
quicksort(arr, low, pos-1);
quicksort(arr, pos+1, high);
}
}
int main(){
int x;
cout<<"Enter the Size of Array";
cin>>x;
cout<<"Enter the elemnt of array";
int arr[x];
for(int a=0; a<x; a++){
cin>>arr[a];
}
quicksort(arr, 0, x-1);
cout<<"the Second array is";
for (int a = 0; a < x; a++)
{
cout<<arr[a]<< "\t";
}
}