Expt 2
Expt 2
Program:
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
struct Node *prev;
};
newNode->data = data;
newNode->next = *head_ref;
newNode->prev = NULL;
if(*head_ref !=NULL)
(*head_ref)->prev = newNode;
*head_ref = newNode;
}
if(current == NULL)
{
printf("List is Empty");
return ;
}
if(current->next == NULL)
{
printf(" value %d , not found \n",delVal);
return ;
}
else
{
//store reference to current link
temp = current;
//move to next link
current = current->next;
}
}
free(current);
return ;
}
if(current == firstnode )
{
//change first to point to next link
*head_ref = firstnode->next;
firstnode->next->prev =NULL;
}
else
{
//bypass the current link
temp->next = current->next;
{
printf("List :");
while (node != NULL)
{
printf(" %d ", node->data);
node = node->next;
}
printf("\n");
int main()
{
display(head);
delete(&head,12);
display(head);
return 0;
}
Output:
List : 22 30 24 20 16 12
value 12 ,deleted
List : 22 30 24 20 16