1 #include2 #include 3 4 using namespace std; 5 6 // 输出集合元素 7 void printSet(list p) 8 { 9 size_t num = p.size();10 if(!num)11 cout<<"空集\n";12 else13 {14 list ::iterator pos = p.begin();15 for( ;pos!= p.end() ; pos++)16 {17 cout<<(*pos)<<"\t";18 }19 cout<<"\n"<
n 说明已经完成的最后元素的选择,输出 27 void GetPowerSet(int i,list a,list &b)28 {29 int n = a.size();30 if(i >= n)31 printSet(b);32 else33 {34 list ::iterator it = a.begin();35 int j = 0;36 while(j++ < i)37 it++;38 int tmp = *it;39 b.push_back(tmp);40 GetPowerSet(i+1,a,b);41 b.pop_back();42 GetPowerSet(i+1,a,b);43 }44 } 45 46 int main(int argc,char* argv[])47 {48 list la,lb;49 la.push_back(10);50 la.push_back(3);51 52 GetPowerSet(0,la,lb); 53 return 0;54 }