- Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathExercise_2.cpp
More file actions
Latest commit
47 lines (42 loc) · 1.11 KB
/
Copy pathExercise_2.cpp
File metadata and controls
47 lines (42 loc) · 1.11 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
#include<bits/stdc++.h>
usingnamespacestd;
// A utility function to swap two elements
voidswap(int* a, int* b)
{
//Your Code here
}
/* This function takes last element as pivot, places
the pivot element at its correct position in sorted
array, and places all smaller (smaller than pivot)
to left of pivot and all greater elements to right
of pivot */
intpartition (int arr[], int low, int high)
{
//Your Code here
}
/* The main function that implements QuickSort
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
voidquickSort(int arr[], int low, int high)
{
//Your Code here
}
/* Function to print an array */
voidprintArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
cout << arr[i] << "";
cout << endl;
}
// Driver Code
intmain()
{
int arr[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(arr) / sizeof(arr[0]);
quickSort(arr, 0, n - 1);
cout << "Sorted array: \n";
printArray(arr, n);
return0;
}