jeudi 5 août 2021

why i am getting some unwanted data in my result

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

 void subsetgeneration(vector<int> input, vector<int> output, int index)
{
    if (index>input.size())
    {
        for (auto i : output)
        {
            cout<<i<<"  ";
        }
        cout<<endl;
        
        return ;
    }
    
    subsetgeneration(input,output,index+1);
    output.push_back(input[index]);
    subsetgeneration(input,output,index+1); 
}


int main()
{
    int  n;
    int k;
    vector<int> input{1,2,3};
    vector<int> output;

    subsetgeneration(input,output,0);
        
}

/* ...........OUTPUT........

2140
3 3 2140 2 2 2140 2 3 2 3 2140 1 1 2140 1 3 1 3 2140 1 2 1 2 2140 1 2 3 1 2 3 0

*/

Aucun commentaire:

Enregistrer un commentaire