-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFordJohnsonAlgorithm.hpp
112 lines (95 loc) · 2.57 KB
/
FordJohnsonAlgorithm.hpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include <iostream>
#include <vector>
#include <deque>
#include <stack>
#include <ctime>
#include <exception>
class FordJohnsonAlgorithm
{
public:
FordJohnsonAlgorithm();
// main function
FordJohnsonAlgorithm(FordJohnsonAlgorithm const &other);
FordJohnsonAlgorithm &operator=(FordJohnsonAlgorithm const &other);
~FordJohnsonAlgorithm();
class PmergeVector
{
private:
std::vector<int> vec;
std::vector<int> positions;
std::vector<std::pair<int, int> > vecPair;
std::vector<int> mainChain;
std::vector<int> pend;
std::vector<int> jacobSequence;
void getIntegerSequence(char *av[]);
// create pair
void createVectorPairs();
// sort pairs
void sortVectorPairs();
// merge sort
void merge(std::vector<std::pair<int, int> > &array, int begin, int mid, int end);
// merge left and right
void mergeSort(std::vector<std::pair<int, int> > &array, int begin, int end);
// create main chain and pend;
void createMainChainAndPend();
// binary search
int binarySearch(std::vector<int> array, int target, int begin, int end);
// generate jacob_insertion_sequence
void generateJacobInsertionSequence();
// jacobsthal index
int jacobsthal(int n);
// generate positions
void generatPositions();
// insert to main chain
void insertToMainChain();
public:
PmergeVector();
~PmergeVector();
void applyMergeInsertSort(char *av[]);
void printBefore();
void printAfter();
};
class PmergeDeque
{
private:
std::deque<int> deque;
std::deque<int> positions;
std::deque<std::pair<int, int> > dequePair;
std::deque<int> mainChain;
std::deque<int> pend;
std::deque<int> jacobSequence;
void getIntegerSequence(char *av[]);
// create pair
void createDequePairs();
// sort pairs
void sortDequePairs();
// merge sort
void merge(std::deque<std::pair<int, int> > &array, int begin, int mid, int end);
// merge left and right
void mergeSort(std::deque<std::pair<int, int> > &array, int begin, int end);
// create main chain and pend;
void createMainChainAndPend();
// binary search
int binarySearch(std::deque<int> array, int target, int begin, int end);
// generate jacob_insertion_sequence
void generateJacobInsertionSequence();
// jacobsthal index
int jacobsthal(int n);
// generate positions
void generatPositions();
// insert to main chain
void insertToMainChain();
public:
PmergeDeque();
~PmergeDeque();
void applyMergeInsertSort(char *av[]);
};
class exception : public std::exception
{
public:
exception();
virtual ~exception() throw();
virtual const char *what() const throw();
};
};