Advertisement
Salman_CUET_18

Subset Generate

Jun 16th, 2020
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n, a[100];
  4. queue<int>q;
  5. void printqueue(queue<int>q)
  6. {
  7.     while (!q.empty())
  8.     {
  9.         cout << q.front() << ' ';
  10.         q.pop();
  11.     }
  12.     cout << endl;
  13. }
  14. void GenerateSubset(int i)
  15. {
  16.     if (i == n)
  17.     {
  18.         printqueue(q);
  19.         return;
  20.     }
  21.     GenerateSubset(i + 1);
  22.     q.push(a[i]);
  23.     GenerateSubset(i + 1);
  24.     q.pop();
  25. }
  26. main()
  27. {
  28.     cin >> n;
  29.     for (int i = 0; i < n; i++) cin >> a[i];
  30.     GenerateSubset(0);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement