0

I wanted to know whether there is any function in C++ similar to the addAll() function in java

I was trying to execute the following program

#include<bits/stdc++.h>
using namespace std;

#define vs vector<string>

void print_Subset(string p, string up)
{
    if(up.empty())
    {    cout<<p<<", ";
          return;
    }    
    char ch = up[0];
    print_Subset(p+ch,up.substr(1));
    print_Subset(p,up.substr(1));
}

vector<string> print_Susbset_String(string p, string up)
{
    if(up.empty())
    {   vector<string> v;
       v.push_back(p);
        return v;
    }
    int i;
    char ch = up[0];
    vector<string> left  = print_Susbset_String(p+ch,up.substr(1));
    vector<string> right = print_Susbset_String(p,up.substr(1));
     
    vector<string> ans;    // I want to combine the left and right answers into this

    

        return ans;
}

int main()
{
    string s="abc";
    vs a;
    a = print_Susbset_String("",s);
    for(auto i: a)
        cout<<i<<",";
}

So I want to return all the subsets of the string "abc" by storing it in a vector of strings

Is there any solution?

0 Answers0