I’m trying to generate all possible subsets for a specific bool vector of size 3. So there should be 8 possible subsets:
#include<iostream>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
using namespace std;
int n = 3;
int mis(vector<bool> f,int i){
for(int j=0; j <f.size();j++)
cout<<f[i]<<" ";
cout<<endl;
f[i] = false;
return mis(f,i+1);
f[i] = true;
return mis(f,i+1);
}
int main(){
vector<bool> f;
f.resize(n);
int m = mis(f,0);
}
I’m getting the following error:
a.out: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted
In fact you did several mistakes. Here the right code:
In the loop that prints the content of
vectoryou use variablejbut printsf[i]. I believe this is the reason of assertion you got.The code
f[i] = true; return mis(f, i + 1);is not reachable. You should use variables to remember the intermediate result as did I.There is no exit from your recursion. You never check whether
iis too big.