Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- box<T>* combineBoxes(box<T>* sorted, box<T>* toAdd) {
- if (!sorted || !toAdd) {
- return nullptr;
- }
- box<T>* result = nullptr;
- box<T>* tempSorted = sorted;
- while (tempSorted != nullptr) {
- push_back(result, tempSorted->data);
- tempSorted = tempSorted->next;
- }
- box<T>* tempToAdd = toAdd;
- tempSorted = result;
- while (tempToAdd != nullptr) {
- size_t index = 0;
- bool elementAdded = false;
- while (tempSorted != nullptr) {
- if (tempSorted->data >= tempToAdd->data) {
- insertAt(result, tempToAdd->data, index);
- elementAdded = true;
- break;
- }
- tempSorted = tempSorted->next;
- index++;
- }
- if (!elementAdded) {
- push_back(result, tempToAdd->data);
- }
- tempSorted = result;
- tempToAdd = tempToAdd->next;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement