Need Help in this generating subset code!

Revision en2, by Sinux, 2024-03-21 15:23:58

void search(int k) { if (k == n) { // process subset } else { search(k+1); subset.push_back(k); search(k+1); subset.pop_back(); } }

I am having a really hard time understand this code. I especially don't understand how 'k' turns to 2 after 'k' reaches 3. I think It's related to the thing backtracking. Someone plz help!!!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Sinux 2024-03-21 15:58:34 103
en2 English Sinux 2024-03-21 15:23:58 19 Tiny change: '\n~~~~~\nYour code here...\nvoid sea' -> '~~~~~\n\nvoid sea'
en1 English Sinux 2024-03-21 15:23:23 443 Initial revision (published)