Code for Doubly Linked List C-programing
#include<stdio.h> #include<conio.h> #include<stdlib.h> struct node { int data; struct node *next; struct node *prev; }; struct node *head; void InsertAtBeginning(int x) { struct node *ptr = (struct node *)malloc(sizeof(struct node)); ptr->next = NULL; ptr->prev = NULL; ptr->data = x; if(ptr==NULL) { printf("\n MEMORY NOT AVAILABLE"); } if(head==NULL) { head = ptr; } else { ptr->next = head; head->prev=ptr; head = ptr; } } void InsertAtEnd(int y) { struct node *ptr = (struct node *)malloc(sizeof(struct node)); struct node *temp; ptr->data = y; ptr->next = NULL; ptr->prev = NULL; if(ptr==NULL) { printf("\n MEMORY NOT AVAILABLE"); } if(head==NULL) { head = ptr; } else { temp = head; while(temp->next!=NULL) { temp = temp->next; } temp->next = ptr; ptr->prev = temp; ptr->next = NULL; } }