#include <stdio.h>
#include <stdlib.h>
struct Node
{
struct Node *prev;
int data;
struct Node *next;
}*head,*tail,*nn,*loc;
int insertValue()
{
int value;
printf("\nInsert Value:");
scanf("%d",&value);
return value;
}
int insertBeg()
{
nn=malloc(sizeof(struct Node));
nn->data=insertValue();
nn->prev=NULL;
if(head==NULL && tail==NULL)
{
head=nn;
tail=nn;
nn->next=NULL;
}
else
{
head->prev=nn;
nn->next=head;
head=nn;
}
return 0;
}
int deleteAfterElement()
{
if(head==NULL && tail==NULL)
return 1;
int ele;
printf("Enter Value To Delete:");
scanf("%d",&ele);
loc=head;
while(loc->next!=NULL)
{
if(loc->next->data==ele){
struct Node *temp;
temp=loc->next;
loc->next->next->prev=loc;
loc->next=loc->next->next;
free(temp->next);
}
loc=loc->next;
}
return 0;
}
int traverseF()
{
if(head==NULL && tail==NULL)
return 0;
loc=head;
while(loc!=NULL)
{
printf("\n%u <- %d -> %u",loc->prev,loc->data,loc->next);
loc=loc->next;
}
return 0;
}
int main()
{
insertBeg();
insertBeg();
insertBeg();
insertBeg();
traverseF();
if(deleteAfterElement(33))
printf("Error!No Values Entered");
traverseF();
return 0;
}
#include <stdlib.h>
struct Node
{
struct Node *prev;
int data;
struct Node *next;
}*head,*tail,*nn,*loc;
int insertValue()
{
int value;
printf("\nInsert Value:");
scanf("%d",&value);
return value;
}
int insertBeg()
{
nn=malloc(sizeof(struct Node));
nn->data=insertValue();
nn->prev=NULL;
if(head==NULL && tail==NULL)
{
head=nn;
tail=nn;
nn->next=NULL;
}
else
{
head->prev=nn;
nn->next=head;
head=nn;
}
return 0;
}
int deleteAfterElement()
{
if(head==NULL && tail==NULL)
return 1;
int ele;
printf("Enter Value To Delete:");
scanf("%d",&ele);
loc=head;
while(loc->next!=NULL)
{
if(loc->next->data==ele){
struct Node *temp;
temp=loc->next;
loc->next->next->prev=loc;
loc->next=loc->next->next;
free(temp->next);
}
loc=loc->next;
}
return 0;
}
int traverseF()
{
if(head==NULL && tail==NULL)
return 0;
loc=head;
while(loc!=NULL)
{
printf("\n%u <- %d -> %u",loc->prev,loc->data,loc->next);
loc=loc->next;
}
return 0;
}
int main()
{
insertBeg();
insertBeg();
insertBeg();
insertBeg();
traverseF();
if(deleteAfterElement(33))
printf("Error!No Values Entered");
traverseF();
return 0;
}
No comments:
Post a Comment