We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84b8b4f commit b63199fCopy full SHA for b63199f
iterator_for_combination.cpp
@@ -0,0 +1,30 @@
1
+class CombinationIterator {
2
+ string s;
3
+ queue<string> q;
4
+
5
+ void getCombination(int start, int length, string txt){
6
+ if(length == 0){
7
+ q.push(txt);
8
+ return;
9
+ }
10
11
+ for(int i = start; i <= s.length() - length; ++i)
12
+ getCombination(i+1, length-1, txt + s[i]);
13
14
+public:
15
+ CombinationIterator(string characters, int combinationLength) {
16
+ s = characters;
17
+ string txt = "";
18
+ getCombination(0, combinationLength, txt);
19
20
21
+ string next() {
22
+ string str = q.front();
23
+ q.pop();
24
+ return str;
25
26
27
+ bool hasNext() {
28
+ return !q.empty();
29
30
+};
0 commit comments