Complete the code to declare a node structure for a doubly linked list.
typedef struct Node {
int data;
struct Node* prev;
struct Node* [1];
} Node;The 'next' pointer points to the next node in the doubly linked list, allowing traversal forward.
Complete the code to create a new node dynamically.
Node* createNode(int value) {
Node* newNode = (Node*)malloc(sizeof([1]));
if (newNode == NULL) return NULL;
newNode->data = value;
newNode->prev = NULL;
newNode->next = NULL;
return newNode;
}We allocate memory for the 'Node' structure type to create a new node.
Fix the error in the function to initialize a doubly linked list node.
void initNode(Node* node, int val) {
node->data = val;
node->prev = NULL;
node->[1] = NULL;
}The pointer to the next node must be set to NULL to mark the end of the list.
Fill both blanks to correctly link two nodes in a doubly linked list.
void linkNodes(Node* first, Node* second) {
first->[1] = second;
second->[2] = first;
}The first node's 'next' points to the second node, and the second node's 'prev' points back to the first node.
Fill all four blanks to insert a new node between two existing nodes.
void insertBetween(Node* prevNode, Node* newNode, Node* nextNode) {
newNode->[1] = nextNode;
newNode->[2] = prevNode;
prevNode->[3] = newNode;
nextNode->[4] = newNode;
}The new node's 'next' points to the next node, its 'prev' points to the previous node, the previous node's 'next' points to the new node, and the next node's 'prev' points to the new node.
