Need Help in this generating subset code!

Правка en1, от Sinux, 2024-03-21 15:23:23
Your code here...
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!!!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Sinux 2024-03-21 15:58:34 103
en2 Английский Sinux 2024-03-21 15:23:58 19 Tiny change: '\n~~~~~\nYour code here...\nvoid sea' -> '~~~~~\n\nvoid sea'
en1 Английский Sinux 2024-03-21 15:23:23 443 Initial revision (published)