Linked List Delete Data




#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int data;
    struct node *next;
    struct node *prev;
};



struct node* getdata(int n)
{
    struct node *current;
    struct node *temp;
    struct node *head;
    current=(struct node*)malloc(sizeof(struct node));
    head=current;
    while(1)
    {
    if(n!=0)
    {
       current->data=n;
       temp=current;
       current=(struct node*)malloc(sizeof(struct node));
       temp->next=current;
       current->prev=temp;
       printf("Enter Number(0 to terminate)\n");
       scanf("%d",&n);


    }
    else
    {
        temp->next=NULL;
        break;

    }
    }
    return head;
}
void print(struct node *head)
{
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        printf("%d    %d    %d\n",temp,temp->data,temp->next);
        temp=temp->next;

    }
    return;


}
struct node* delete_1(struct node *head)
{
    struct node *ihead,*lhead,*uhead,*phead;
    uhead=head;
    int a;
    printf("Which Data You want to Delete=");
    scanf("%d",&a);
    while(uhead->data!=a)
    {
        uhead=uhead->next;
    }
    lhead=uhead;
    ihead=lhead->next;
    phead=lhead->prev;
    phead->next=ihead;




}
int main()
{
    int n;
    printf("Enter Data=");
    scanf("%d",&n);
    struct node *head;
    head=getdata(n);
    print(head);
    delete_1(head);
    print(head);

}


Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment