-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexSortClass.h
78 lines (71 loc) · 1.62 KB
/
ComplexSortClass.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#ifndef COMPLEXSORTCLASS_H
#define COMPLEXSORTCLASS_H
#include "ComplexCoreClass.h"
TemplateDefinition
class ComplexSortClass : ComplexCoreClass <TemplateParameter>
{
public:
ComplexSortClass()
{
// dont call base class default constructor directly, icc has problem with it.
// default constructor of base class automatically called befor constructor of derived class.
// but parametrized constructor of base class should be called explicitly.
}
ComplexSortClass(MemoryManagerClass *MemoryManager) : BaseConstructor
{
}
void QuickSort(Ts* A, int FirstIndex, int LastIndex)
{
int r;
if (FirstIndex < LastIndex)
{
r = QuickSort_Partition(A, FirstIndex, LastIndex);
QuickSort(A, FirstIndex, r);
QuickSort(A, r + 1, LastIndex);
}
}
int QuickSort_Partition(Ts* A, int FirstIndex, int LastIndex)
{
Ts x = A[FirstIndex];
int i = FirstIndex;
int j;
for (j = FirstIndex + 1; j < LastIndex; j++)
{
if (A[j] <= x)
{
i = i + 1;
swap(A[i], A[j]);
}
}
swap(A[i], A[FirstIndex]);
return i;
}
void QuickSort(Ta A, int FirstIndex, int LastIndex)
{
int r;
if (FirstIndex < LastIndex)
{
r = QuickSort_Partition(A, FirstIndex, LastIndex);
QuickSort(A, FirstIndex, r);
QuickSort(A, r + 1, LastIndex);
}
}
int QuickSort_Partition(Ta A, int FirstIndex, int LastIndex)
{
Ts x = A[FirstIndex];
int i = FirstIndex;
int j;
for (j = FirstIndex + 1; j < LastIndex; j++)
{
if (A[j] <= x)
{
i = i + 1;
swap(A[i], A[j]);
}
}
swap(A[i], A[FirstIndex]);
return i;
}
};
#endif