Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. vector<vector<int>> weave(vector<int> rhs,
  2. vector<int> lhs,
  3. vector<int> prefix = vector<int>())
  4. {
  5. vector<vector<int>> output;
  6. if(rhs.empty())
  7. {
  8. auto single = prefix;
  9. single.insert(single.end(), lhs.begin(), lhs.end());
  10. output.push_back(single);
  11. }
  12. else if (lhs.empty())
  13. {
  14. auto single = prefix;
  15. single.insert(single.end(), rhs.begin(), rhs.end());
  16. output.push_back(single);
  17. }
  18. else
  19. {
  20. // LHS
  21. auto lhs_short = lhs;
  22. auto lhs_prefix = prefix;
  23. lhs_prefix.push_back(lhs_short.front());
  24. lhs_short.erase(lhs_short.begin());
  25. auto lhs_weaved = weave(rhs, lhs_short, lhs_prefix);
  26. output.insert(output.end(), lhs_weaved.begin(), lhs_weaved.end());
  27. // RHS
  28. auto rhs_short = rhs;
  29. auto rhs_prefix = prefix;
  30. rhs_prefix.push_back(rhs_short.front());
  31. rhs_short.erase(rhs_short.begin());
  32. auto rhs_weaved = weave(lhs, rhs_short, rhs_prefix);
  33. output.insert(output.end(), rhs_weaved.begin(), rhs_weaved.end());
  34. }
  35. return output;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement