Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- LList<T> combineLists(const LList<T>& sorted, const LList<T>& toAdd) {
- LList<T> result = sorted;
- for (size_t i = 0; i < toAdd.size(); ++i) {
- size_t index = 0;
- if (toAdd[i] <= result[0]) {
- result.push(toAdd[i]);
- continue;
- }
- for (size_t j = 1; j < result.size(); j++) {
- size_t prev = j - 1;
- if (result[j] >= toAdd[i] && result[prev] <= toAdd[i]) {
- index = j;
- break;
- }
- }
- result.insertAt(index, toAdd[i]);
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement