# C++: Combining two circular, doubly linked lists

Given two circular, doubly linked lists, write a function that combines them.

    //--- Node for doubly linked list of floats.
    struct Node {
        Node* next;  // Pointer to next element
        Node* prev;  // Pointer to previous element
        float data;
    };

    //--- Function prototype
    Node* splice(Node* p, Node* q);

The `splice()` function should do the following:

- This should return the the combined list.
- Elements of q should be placed after the element that p points to. They should be linked into the list p, not copied.
- Return p if it isn't NULL, otherwise return q.

Answer