kebria

Creating a node (Doubly Linked List)

Jun 16th, 2021
569
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* A doubly linked list is different from a singly linked list in a way that each node has a extra pointer that pointes to the previous node, together with the next pointer and data similar to singly linked list */
  2. /* Creating a Node */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. struct node {
  7.     struct node *prev;
  8.     int data;
  9.     struct node *next;
  10. };
  11.  
  12. int main()
  13. {
  14.     struct node *head = malloc(sizeof(struct node));
  15.     head->prev = NULL;
  16.     head->data = 10;
  17.     head->next = NULL;
  18.  
  19.     printf("%d", head->data);
  20.     return 0;
  21. }
  22.  
  23. /* Output: 10 */
RAW Paste Data