Doubly linked list of 4 nodes

PHOTO EMBED

Sun May 14 2023 19:21:14 GMT+0000 (Coordinated Universal Time)

Saved by @prachi

#include <stdio.h>
#include<stdlib.h>
struct node 
{
  struct node *prev;
  int data;
  struct node *next;
};
void print_linked_list(struct node *next);

int main()
{
  struct node *first;
  struct node *second;
  struct node *third;
  struct node *fourth;
  first = (struct node *) malloc(sizeof(struct node));
  second = (struct node *) malloc(sizeof(struct node));
  third = (struct node *) malloc(sizeof(struct node));
  fourth = (struct node *) malloc(sizeof(struct node));
  int a,b,c,d;
  printf("Enter the data\n",a,b,c,d);
  scanf("%d %d %d %d",&a,&b,&c,&d);
  first->prev=NULL;
  first->data=a;
  first->next=second;
  second->prev=first;
  second->data=b;
  second->next=third;
  third->prev=second;
  third->data=c;
  third->next=fourth;
  fourth->prev=third;
  fourth->data=d;
  fourth->next=NULL;
  print_linked_list(first);
  return 0;
}
void print_linked_list(struct node *n)
{
  while(n!=NULL)
    {
      printf("%d %d %d\n",n->prev,n->data,n->next);
      n=n->next;
    }
}
content_copyCOPY