-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCombinations.cpp
34 lines (29 loc) · 966 Bytes
/
Combinations.cpp
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
//
// Created by max on 29.04.21.
//
#include "Combinations.h"
#include <vector>
#include <string>
#include <iostream>
using std::string;
using std::vector;
using std::cout;
using std::endl;
/// The method used to recursively compute all possible combinations.
/// \param input The input from which to compute all combinations of.
/// \param IDK myself.
void Combinations::compute(const string& input, const string& result) {
if (result.length() == _size) {
_combinations.push_back(result);
}
for( int i = 0; i < input.length(); i++ )
compute(string(input).erase(i, 1), result + input[i]);
}
/// Start the process of computing all combinations.
/// \param input The string from which to compute the combinations of.
/// \return A vector which holds all possible combinations.
std::vector<std::string> Combinations::allCombinations(const string& input) {
_size = input.length();
compute(input,"");
return _combinations;
}