I have written a code for a coding question on the leetcode. Question is that we are given a vector and we have to find all the permutation of that vector. I have tried this question using bitmasking.
My code:
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> vec;
vector<int> v1;
vector<int> nums{ 1, 2, 3 };
void fun(int mask, vector<int> nums)
{
int n = nums.size();
int j;
if (mask == 0)
{
vec.push_back(v1);
for(int i=0;i<v1.size();i++)
{
cout << v1[i] << " ";
}
cout << endl;
return;
}
for (j = 0; j < n; j++)
{
if (mask & (1 << j))
{
v1.push_back(nums[j]);
fun(mask ^ (1 << j), nums);
v1.pop_back();
}
}
return;
}
int main()
{
int n = 3;
int mask = (1 << (n)) - 1;
fun(mask, nums);
}
Somehow,i am getting all the permutation of the given permutation. My only question is that I am not able to draw the recursive tree for this question. Is there any website or app available online, in which I can insert my above-mentioned code and that website or app will produce the recursive tree online???
Can anyone please help me in finding any such websites to draw and visualize recursive tree online?