Finance[US] Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
554 views
in RTU/BTU B.Tech(CSE-III Sem) DSA LAB by Goeduhub's Expert (5.8k points)
Deletion after the specified node  in Doubly Linked List

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Deletion after the specified node  in Doubly Linked List

deletion after the specified node in doubly linked list

Algorithm

    Write UNDERFLOW
   Go to Step 9
  [END OF IF]

   [END OF LOOP]

  • Step 1: IF HEAD = NULL
  • Step 2: SET TEMP = HEAD
  • Step 3: Repeat Step 4 while TEMP -> DATA != ITEM
  • Step 4: SET TEMP = TEMP -> NEXT
  • Step 5: SET PTR = TEMP -> NEXT
  • Step 6: SET TEMP -> NEXT = PTR -> NEXT
  • Step 7: SET PTR -> NEXT -> PREV = TEMP
  • Step 8: FREE PTR
  • Step 9: EXIT

Program Code

#include<stdio.h>  

#include<stdlib.h>  

#include<conio.h>

void create(int);  

void delete_specified();  

struct node  

{  

    int data;  

    struct node *next;  

    struct node *prev;  

};  

struct node *head;  

void main ()  

{  

     clrscr();    

     int choice,item;  

    do   

    {  

        printf("1.Append List\n2.Delete node\n3.Exit\nEnter your choice: ");  

        scanf("%d",&choice);  

        switch(choice)  

        {  

            case 1:  

            printf("Enter the item: ");  

            scanf("%d",&item);  

            create(item);  

            break;   

            case 2:  

            delete_specified();  

            break;   

            case 3:  

            exit(0);  

            break;    

            default:  

            printf("Please enter valid choice\n\n");  

        }         

    }while(choice != 3);  

}  

void create(int item)  

{  

   struct node *ptr = (struct node *)malloc(sizeof(struct node));  

   if(ptr == NULL)  

   {  

       printf("OVERFLOW\n\n");  

   }  

   else  

   {  

   if(head==NULL)  

   {  

       ptr->next = NULL;  

       ptr->prev=NULL;  

       ptr->data=item;  

       head=ptr;  

   }  

   else   

   {  

       ptr->data=item;  

       ptr->prev=NULL;  

       ptr->next = head;  

       head->prev=ptr;  

       head=ptr;  

   }  

    printf("Node Inserted\n\n");  

}  

     

}  

void delete_specified( )  

{  

    struct node *ptr, *temp;   

    int val;   

    printf("Enter the value: ");  

    scanf("%d",&val);  

    temp = head;  

    while(temp -> data != val)  

    temp = temp -> next;  

    if(temp -> next == NULL)  

    {  

        printf("Can't delete\n\n");

    }  

    else if(temp -> next -> next == NULL)  

    {  

        temp ->next = NULL;  

        printf("Node Deleted\n\n");  

    }  

    else

    {

        ptr = temp -> next;

        temp -> next = ptr -> next;

        ptr -> next -> prev = temp;

        free(ptr);

        printf("Node Deleted\n\n");

    }     

}  

Output


For more Data Structures & Algorithms Tutorials Click here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...