programminginc.net

C Language Programming

  • Home
  • C Examples
Home > Data Structure C Programming Examples > Deletion in doubly linked list data structure Using C Program

Deletion in doubly linked list data structure Using C Program

Deletion in doubly linked list data structure Using pointer in C Program. The program shows delete operation of a node from beginning, middle and end

//deletion in doubly linked list # //
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct doublelist
{int info;
struct doublelist *next, *prev;
};
typedef struct doublelist node;
node* makenode(int);
void delmid(node*);
void delend(node*);
node* delbeg(node*);
void display(node*);
main()
{
node *head, *p, *z;
int x; char c='y';
clrscr();
printf("Enter the number");
scanf("%d", &x);
head=makenode(x);
p=head;
printf("Do you want to continue");
fflush(stdin);
scanf("%c", &c);
while(c!='n')
{
printf("Enter the number");
scanf("%d", &x);
z=makenode(x);
p->next=z;
z->prev=p;
p=z;
printf("\n\nDo you want to continue");
fflush(stdin);
scanf("%c", &c);
}
printf("\n\nThe linked list is ");
display(head);
printf("\n\n");
printf("This function delete from mid");
delmid(head);
printf("\n\nThe list after mid del is");
display(head);
printf("\n\nThis function delete from begenning");
head=delbeg(head);
printf("\n\nThe list after beg del is");
display(head);
printf("\n\nThis function delege from end");
delend(head);
printf("\n\nThe list after end del is");
display(head);
getch();
return 0;
}
node* makenode(int x)
{
node *z;
z=(node*)malloc(sizeof(node));
z->info=x;
z->prev=NULL;
z->next=NULL;
return z;
}
void delmid(node *head)
{int k;
node *p, *q;
printf("Enter the number to delete");
scanf("%d", &k);
for(p=head; p->next->info!=k; p=p->next);
q=p->next;
p->next=q->next;
p->next=q->next;
q->next->prev=p;
free(q);
}
void display(node *head)
{
node *p, *z;
p=head;
while(p!=NULL)
{z=p;
printf("\t%d", p->info);
p=p->next;
}
while(z!=NULL)
{printf("\t%d", z->info);
z=z->prev;}
}
node* delbeg(node *head)
{node *p;
p=head;
head=head->next;
head->prev=NULL;
free(p);
return head;
}
void delend(node *head)
{
node *p, *q;
int k;
for (p=head; p->next->next!=NULL; p=p->next);
q=p->next;
p->next=NULL;
free(q);
}
//end of program//
  • Singly Linked List Data Structure Program C
  • C program to insert a node in singly linked list
  • Doubly linked list in data structure using C Program
  • Insertion in doubly linked list data structure Using C Program
  • Deletion in doubly linked list data structure Using C Program

Copyright © 2021  programminginc.net