Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node {
- int key;
- struct Node *next;
- struct Node *prev;
- } *start1 = nullptr, *start2 = nullptr;
- struct Node * merge_list(struct Node * head1, struct Node * head2)
- {
- struct Node* head3 = nullptr;
- struct Node* p1 = head1;
- struct Node* p2 = head2;
- struct Node* p3 = nullptr;
- while (p1 != nullptr || p2 != nullptr)
- {
- struct Node * tmp = nullptr;
- if (p1 == NULL) {
- tmp = p2;
- p2 = NULL;
- } else if (p2 == nullptr) {
- tmp = p1;
- p1 = NULL;
- }
- if ((p1 != nullptr) && (p2 != nullptr)) {
- if (p1->key < p2->key) {
- tmp = p1;
- p1 = p1->next;
- } else {
- tmp = p2;
- p2 = p2->next;
- }
- }
- if (head3 == nullptr) {
- head3 = tmp;
- } else {
- p3->next = tmp;
- tmp->prev = p3;
- }
- p3 = tmp;
- }
- return head3;
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement