Есть программа: #include <iostream>
#include <string>
using namespace std;

class Node //элемент списка
{
public:
    int data;
    Node* prev, * next;
public:
    Node(int data)
    {
        this->data = data;
        this->prev = this->next = NULL;
    }
};

class LinkedList //список
{
public:
    Node* head, * tail;

public:
    LinkedList() //1.Инициализация
    {
        head = tail = NULL;
    }

    void freeMemory() //2.Освобождение памяти 
    {
        if (head == NULL)
            return;

        Node* current = head;
        Node* nextNode;

        do
        {
            nextNode = current->next;
            delete current;
            current = nextNode;
        } while (current != head);

        head = tail = NULL;
    }

    void addSorted(int data) //3.Добавление элемента в порядке возрастания
    {
        Node* newNode = new Node(data);

        if (head == NULL) //если список пустой
        {
            head = tail = newNode;
            newNode->next = newNode->prev = newNode;
        }
        else if (data < head->data) //если новый элемент меньше головы списка
        {
            newNode->next = head;
            newNode->prev = tail;
            tail->next = newNode;
            head->prev = newNode;
            head = newNode;
        }
        else if (data > tail->data) //если новый элемент больше хвоста списка
        {
            newNode->next = head;
            newNode->prev = tail;
            tail->next = newNode;
            head->prev = newNode;
            tail = newNode;
        }
        else // если новый элемент располагается где-то в середине списка
        {
            Node* current = head->next;

            while (current != head && current->data < data)
            {
                current = current->next;
            }

            newNode->next = current;
            newNode->prev = current->prev;
            current->prev->next = newNode;
            current->prev = newNode;
        }
    }

    void removeBefore(int data)
    {
        if (head == NULL)
            return;

        Node* current = head->next;

        while (current != head)
        {
            if (current->data == data)
            {
                Node* nodeToRemove = current->prev;
                nodeToRemove->prev->next = current;
                current->prev = nodeToRemove->prev;
                delete nodeToRemove;
            }

            current = current->next;
        }

        if (head->data == data)
        {
            Node* nodeToRemove = tail;
            nodeToRemove->prev->next = head;
            head->prev = nodeToRemove->prev;
            tail = nodeToRemove->prev;
            delete nodeToRemove;
        }
    }

    Node* search(int data)
    {
        if (head == NULL)
            return NULL;

        Node* current = head;

        do
        {
            if (current->data == data)
                return current;

            current = current->next;
        } while (current != head);

        return NULL;
    }

    void print()
    {
        if (head == NULL)
            return;

        Node* current = head;

        do
        {
            cout << current->data << " ";
            current = current->next;
        } while (current != head);

        cout << endl;
    }

    LinkedList difference(LinkedList& list1, LinkedList& list2) //вычитание из первого списка второго
    {
        LinkedList result;

        Node* current = list1.head;

        do
        {
            if (list2.search(current->data) == NULL)
                result.addSorted(current->data);
            current = current->next;
        } while (current != list1.head);
        return result;
    }
};

int main()
{
    LinkedList list1, list2;

    list1.addSorted(10);
    list1.addSorted(21);
    list1.addSorted(5);

    list2.addSorted(90);
    list2.addSorted(5);

    LinkedList result = list1.difference(list1, list2);

    result.print();
}
Можешь ли подробно объяснить вот эту часть: else // если новый элемент располагается где-то в середине списка
        {
            Node* current = head->next;

            while (current != head && current->data < data)
            {
                current = current->next;
            }

            newNode->next = current;
            newNode->prev = current->prev;
            current->prev->next = newNode;
            current->prev = newNode;
        }