fork download
  1. #include "stdlib.h" /* library header for memory allocation functions*/
  2. #include <stdio.h> /* I/O library header for input/output functions*/
  3. #include "doubly.h"
  4.  
  5. /* Function to insert a new node at the beginning of a doubly linked list*/
  6. Node *insert_at_begin(Node **head, int data)
  7. {
  8. /*Allocate memory for the new node and check if the allocation was successful*/
  9. Node *newNode = malloc(sizeof(Node));
  10. if (newNode == NULL)
  11. {
  12. return (NULL); /*If memory allocation failed, return NULL*/
  13. }
  14.  
  15. newNode->data = data;
  16. newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
  17. newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
  18.  
  19. head->prev = newNode;
  20. /*Update the head of the list to point to the new node*/
  21. *head = newNode; /*
  22. is this extra line correct #include "stdlib.h" /* library header for memory allocation functions*/
  23. #include <stdio.h> /* I/O library header for input/output functions*/
  24. #include "doubly.h"
  25.  
  26. /* Function to insert a new node at the beginning of a doubly linked list*/
  27. Node *insert_at_begin(Node **head, int data)
  28. {
  29. /*Allocate memory for the new node and check if the allocation was successful*/
  30. Node *newNode = malloc(sizeof(Node));
  31. if (newNode == NULL)
  32. {
  33. return (NULL); /*If memory allocation failed, return NULL*/
  34. }
  35.  
  36. newNode->data = data;
  37. newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
  38. newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
  39.  
  40. is this extra line correct #include "stdlib.h" /* library header for memory allocation functions*/
  41. #include <stdio.h> /* I/O library header for input/output functions*/
  42. #include "doubly.h"
  43.  
  44. /* Function to insert a new node at the beginning of a doubly linked list*/
  45. Node *insert_at_begin(Node **head, int data)
  46. {
  47. /*Allocate memory for the new node and check if the allocation was successful*/
  48. Node *newNode = malloc(sizeof(Node));
  49. if (newNode == NULL)
  50. {
  51. return (NULL); /*If memory allocation failed, return NULL*/
  52. }
  53.  
  54. newNode->data = data;
  55. newNode->prev = NULL; /* Set the previous pointer of the new node to NULL, as it will be the first node in the list*/
  56. newNode->next = *head; /* Set the next pointer of the new node to the current head of the list*/
  57.  
  58. /* Update the prev pointer of the node that head is currently pointing to. */
  59. if (*head != NULL)
  60. {
  61. (*head)->prev = newNode;
  62. }
  63. /*Update the head of the list to point to the new node*/
  64. *head = newNode;
  65.  
  66. /*Return the updated head of the list*/
  67. return (*head);
  68. }
  69. *head->prev = newNode;
  70. /*Update the head of the list to point to the new node*/
  71. *head = newNode;
  72.  
  73. /*Return the updated head of the list*/
  74. return (*head);
  75. }*/
  76.  
  77. /*Return the updated head of the list*/
  78. return (*head);
  79. }
  80.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:10: fatal error: doubly.h: No such file or directory
 #include "doubly.h"
          ^~~~~~~~~~
compilation terminated.
stdout
Standard output is empty