#include "stdlib.h" /* library header for memory allocation functions*/
#include <stdio.h> /* I/O library header for input/output functions*/
#include "doubly.h"
/* Function to insert a new node at the beginning of a doubly linked list*/
Node *insert_at_begin(Node **head, int data)
{
/*Allocate memory for the new node and check if the allocation was successful*/
Node
*newNode
= malloc(sizeof(Node
)); if (newNode == NULL)
{
return (NULL); /*If memory allocation failed, return NULL*/
}
newNode->data = data;
newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
head->prev = newNode;
/*Update the head of the list to point to the new node*/
*head = newNode; /*
is this extra line correct #include "stdlib.h" /* library header for memory allocation functions*/
#include <stdio.h> /* I/O library header for input/output functions*/
#include "doubly.h"
/* Function to insert a new node at the beginning of a doubly linked list*/
Node *insert_at_begin(Node **head, int data)
{
/*Allocate memory for the new node and check if the allocation was successful*/
Node
*newNode
= malloc(sizeof(Node
)); if (newNode == NULL)
{
return (NULL); /*If memory allocation failed, return NULL*/
}
newNode->data = data;
newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
is this extra line correct #include "stdlib.h" /* library header for memory allocation functions*/
#include <stdio.h> /* I/O library header for input/output functions*/
#include "doubly.h"
/* Function to insert a new node at the beginning of a doubly linked list*/
Node *insert_at_begin(Node **head, int data)
{
/*Allocate memory for the new node and check if the allocation was successful*/
Node
*newNode
= malloc(sizeof(Node
)); if (newNode == NULL)
{
return (NULL); /*If memory allocation failed, return NULL*/
}
newNode->data = data;
newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
/* Update the prev pointer of the node that head is currently pointing to. */
if (*head != NULL)
{
(*head)->prev = newNode;
}
/*Update the head of the list to point to the new node*/
*head = newNode;
/*Return the updated head of the list*/
return (*head);
}
*head->prev = newNode;
/*Update the head of the list to point to the new node*/
*head = newNode;
/*Return the updated head of the list*/
return (*head);
}*/
/*Return the updated head of the list*/
return (*head);
}