-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLL_DeletionAtFirst.c
47 lines (47 loc) · 1.04 KB
/
DLL_DeletionAtFirst.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdlib.h>
#include<stdio.h>
struct node
{
struct node *prev;
int data;
struct node *next;
};
//Traverse a doubly linked list
void TraverseDoubly(struct node *head)
{
struct node *p = head;
while(p!=NULL)
{
printf("\nElement is: %d",p->data);
p = p->next;
}
}
struct node *deletionAtFirst(struct node *head)
{
struct node *p = head;
head = head->next;
free(p);
return head;
}
int main()
{
struct node *head = malloc(sizeof(struct node));
struct node *second = malloc(sizeof(struct node));
struct node *third = malloc(sizeof(struct node));
struct node *fourth = malloc(sizeof(struct node));
head->prev=NULL;
head->data=10;
head->next=second;
second->prev=head;
second->data=20;
second->next=third;
third->prev=second;
third->data=30;
third->next=fourth;
fourth->prev=third;
fourth->data=40;
fourth->next=NULL;
head = deletionAtFirst(head);
TraverseDoubly(head);
return 0;
}