Language: C++

#include <iostream>

namespace detail
{
    struct node
    {
        int n;
        node* prev;
        node* next;

        node(int x)
            : n(x), prev(nullptr), next(nullptr) {}
    };

    struct list
    {
        node* head;
        node* tail;

        list()
            : head(nullptr), tail(nullptr) {}

        void insert(int n) {
            node* x = new node(n);
            x->next = head;
            if (head != nullptr) {
                head->prev = x;
            } else {
                tail = x;
            }
            head = x;
        }

        node* find(int x) {
            node* it = head;
            while (it != nullptr) {
                if (it->n == x) {
                    return it;
                }
                it = it->next;
            }
            return it;
        }

        void remove(node* it) {
            if (it == nullptr) {
                return;
            }
            if (it == head) {
                head = it->next;
            }
            if (it == tail) {
                tail = it->prev;
            }
            if (it->prev != nullptr) {
                it->prev->next = it->next;
            }
            if (it->next != nullptr) {
                it->next->prev = it->prev;
            }
            delete it;
        }

        void remove(int x) {
            remove(find(x));
        }

        void removeFirst() {
            remove(head);
        }

        void removeLast() {
            remove(tail);
        }
    };
}


void print_list(detail::list& list)
{
    detail::node* node = list.head;
    while (node != list.tail) {
        cout << node->n << " ";
        node = node->next;
    }
    if (list.tail != nullptr) {
        cout << list.tail->n << endl;
    }
}

int main()
{
    detail::list list;

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int x;
        string c;
        cin >> c;
        if (c == "insert") {
            cin >> x;
            list.insert(x);
        } else if (c == "delete") {
            cin >> x;
            list.remove(x);
        } else if (c == "deleteFirst")
            list.removeFirst();
        else if (c == "deleteLast")
            list.removeLast();

        // print_list(list);
        // cerr << "head:" << list.head->n << endl;
        // cerr << "tail:" << list.tail->n << endl;
    }
    print_list(list);

    return 0;
}

Compiler output:
a.cc: In function 'void print_list(detail::list&)':
a.cc:83:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   83 |         cout << node->n << " ";
      |         ^~~~
      |         std::cout
In file included from a.cc:1:
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:87:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   87 |         cout << list.tail->n << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:87:33: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   87 |         cout << list.tail->n << endl;
      |                                 ^~~~
      |                                 std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:96:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   96 |     cin >> n;
      |     ^~~
      |     std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:100:9: error: 'string' was not declared in this scope
  100 |         string c;
      |         ^~~~~~
a.cc:100:9: note: suggested alternatives:
In file included from /usr/include/c++/14/iosfwd:41,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:101:16: error: 'c' was not declared in this scope
  101 |         cin >> c;
      |                ^