Powerset problem in recursion

pull/1275/head
anirudhgeek21 2023-10-23 14:58:34 +05:30
parent d3c2184af8
commit 9b154bf064
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
//Program to get all the subsets/powersets of any array
#include <iostream>
#include <vector>
using namespace std;
void GetSubsets(int nums[],int index,vector<int> arr1,int n){
if(index == n){
for(auto it:arr1){
cout<< it<<" ";
}
cout<<endl;
return ;
}else{
arr1.push_back(nums[index]);
GetSubsets(nums,index+1,arr1,n);
arr1.pop_back();
GetSubsets(nums,index+1,arr1,n);
}
}
//Test case
int main(){
int arr2[]={3,1,2};
int index=0;
int n=3;
vector<int> arr3;
GetSubsets( arr2 ,index,arr3,n);
}