Problems with code
#include <iostream> struct Node{ int n = 0; Node* next = nullptr; Node* prev = nullptr; }; void addNode(Node **n, Node **head, int x){ //problem starts from here if(n){ *n->next = new Node; *n->next->n = x; *n->prev = *n; *n = *n->next; std::cout << *n->n << " " << *head->*next->n; *n->next = nullptr; } else{ *n = new Node; *head = *n; *head->n = x; *head->next = nullptr; *head->prev = nullptr; std::cout << *n->n << *head->n; } } void printNode(Node *n){ if(n!=nullptr){ while(n->prev!=nullptr){ std::cout << n->n; n = n->prev; } } } int main() { Node *n = nullptr; Node *head = nullptr; addNode(&n, &head, 2); addNode(&n, &head, 4); printNode(head); return 0; } If you don't understand what it does then ask, i will answerâș