-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSortSocial.cpp
More file actions
59 lines (47 loc) · 1.36 KB
/
QuickSortSocial.cpp
File metadata and controls
59 lines (47 loc) · 1.36 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
50
51
52
53
54
55
56
57
58
59
// 2018556502 Muhammed Ali ARICI
// 2019556461 Mahmut Can CINGI
// 2020556061 Emre ULUSOY
#include <iostream>
using namespace std;
template <class SWAP>void swapargs( SWAP &x, SWAP &y ) {
SWAP temp;
temp = x;
x = y;
y = temp;
}
template <class temp1, class temp2> void display( temp1 *array, temp2 size) {
for (int i = 0; i < size; i++) {
cout << array[i] << " ";
}
cout << endl;
}
template <class temp1, class temp2, class temp3> int partition( temp1 *array, temp2 primier, temp3 last_element) {
int pivot = array[last_element];
int m = primier - 1;
for (int n = primier; n <= (last_element - 1); n++) {
if ( array[n] <= pivot)
{
m++;
swapargs(array[m], array[n]);
}
}
swapargs(array[m+1], array[last_element]);
return (m+1);
}
template <class temp1, class temp2, class temp3> void quicksort(temp1 *array, temp2 primier, temp3 last_element) {
if (primier < last_element) {
int piv = partition(array, primier, last_element);
quicksort(array, primier,piv -1);
quicksort(array, piv+1, last_element);
}
}
int main(void) {
int x[11] = {53, 5, 1, 12, 19, 46, 24, 34, 51, 9, 15};
int size = sizeof(x) / sizeof(x[0]);
quicksort(x,0,size -1);
display(x,size);
char y[10] = {'y', 'i', 'f', 'c', 'o', 's', 't', 'k', 'a', 'h'};
size = sizeof(y) / sizeof(y[0]);
quicksort(y,0,size -1);
display(y,size);
}