Загрузка данных


#include <iostream>

struct Node {
    int data;
    Node* next = nullptr;
    Node* prev = nullptr;
};

// Добавление в конец
void push_back(Node*& head, Node*& tail, int value) {
    Node* node = new Node{value, nullptr, tail};
    if (tail) tail->next = node;
    else head = node;
    tail = node;
}

// Удаление с конца
void pop_back(Node*& head, Node*& tail) {
    if (!tail) return;
    Node* temp = tail;
    tail = tail->prev;
    if (tail) tail->next = nullptr;
    else head = nullptr;
    delete temp;
}

int main() {
    Node* head = nullptr;
    Node* tail = nullptr;

    push_back(head, tail, 10);
    push_back(head, tail, 20);
    push_back(head, tail, 30);

    // Вывод списка
    for (Node* curr = head; curr; curr = curr->next) 
        std::cout << curr->data << " "; // 10 20 30

    // Очистка памяти
    while (head) pop_back(head, tail);
}