-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutation.h
64 lines (55 loc) · 1.81 KB
/
permutation.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
#ifndef CPP_ALGORITHM_PERMUTATION_H
#define CPP_ALGORITHM_PERMUTATION_H
#include <string>
#include <vector>
namespace Permutation
{
/**
* \brief Permutation from a given string.
* \param str input string
* \param prefix prefix
*/
void Permutation(const std::string& str, const std::string& prefix);
/**
* \brief Permute the elements of an array.
* \param permutation permutation array
* \param arr array
* \return result array
*/
auto ApplyPermutationWithAdditionalSpace(const std::vector<int>& permutation, const std::vector<char>& arr)
-> std::vector<char>;
/**
* \brief Permute the elements of an array. (in-place)
* \param permutation permutation array
* \param arr array
* \return result array
*/
auto ApplyPermutationBySwap(std::vector<int>& permutation, std::vector<char>& arr) -> std::vector<char>;
/**
* \brief Inverse permutation.
* \param permutation permutation array
* \param arr array
* \return inverse array
*/
auto InversePermutation(const std::vector<int>& permutation, const std::vector<char>& arr) -> std::vector<int>;
/**
* \brief Compute the next permutation.
* \param permutation array
* \return next permutation array
*/
auto NextPermutation(std::vector<int>& permutation) -> std::vector<int>;
/**
* \brief Compute the previous permutation.
* \param permutation array
* \return previous permutation array
*/
auto PreviousPermutation(std::vector<int>& permutation) -> std::vector<int>;
/**
* \brief Compute the k-th permutation.
* \param permutation array
* \param k k-th index
* \return k-th permutation array
*/
auto KthPermutation(std::vector<int>& permutation, int k) -> std::vector<int>;
}
#endif