-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallSubsets.cc
More file actions
56 lines (49 loc) · 1.15 KB
/
Copy pathallSubsets.cc
File metadata and controls
56 lines (49 loc) · 1.15 KB
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
// printout all combinations of an array with unique values
// for example: all subsets of {1,2,5,6}
// {1}, {2}, {5}, {6}, {1,2}, {1,2,3}, {1,2,5}, {1,2,5,6}, {2,5}, {2,6}, {2,5,6}, {5,6}
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
//master test...
using namespace std;
struct charInt{
int i;
vector<int> vals;
};
void printoutSubSets(vector<int> v) {
queue<charInt> s;
for(vector<int>::iterator it = v.begin(); it < v.end(); ++it){
charInt ci;
ci.i = it-v.begin();
vector<int> tmp;
tmp.push_back(*it);
ci.vals = tmp;
s.push(ci);
}
while(!(s.empty())){
charInt top = s.front();
s.pop();
vector<int> vi = top.vals;
cout << "(";
for(vector<int>::iterator it = vi.begin(); it < vi.end(); ++it){
cout << *it;
if(it != vi.end()-1){
cout << ",";
}
}
cout << ") ";
for(vector<int>::iterator it = v.begin()+top.i+1; it < v.end();++it){
charInt newCi;
newCi.i = it-v.begin();
newCi.vals = top.vals;
newCi.vals.push_back(*it);
s.push(newCi);
}
}
}
int main() {
vector<int> vv{1, 2, 5, 6};
printoutSubSets(vv);
return 0;
}