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

1 Answer

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

Deletion at the end in Doubly Linked List

deletion at the end in doubly linked list

Algorithm

Write UNDERFLOW 
Go to Step 7
[END OF IF]

[END OF LOOP]

  • Step 1: IF HEAD = NULL
  • Step 2: SET TEMP = HEAD
  • Step 3: REPEAT STEP 4 WHILE TEMP->NEXT != NULL
  • Step 4: SET TEMP = TEMP->NEXT
  • Step 5: SET TEMP ->PREV-> NEXT = NULL
  • Step 6: FREE TEMP
  • Step 7: EXIT

Program Code

#include<stdio.h>  

#include<stdlib.h>  

#include<conio.h>

void create(int);  

void last_delete();  

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 from end\n3.Exit\nEnter your choice: ");  

        scanf("%d",&choice);  

        switch(choice)  

        {  

            case 1:  

            printf("Enter the item: ");  

            scanf("%d",&item);  

            create(item);  

            break;   

            case 2:  

            last_delete();  

            break;   

            case 3:  

            exit(0);  

            break;    

            default:  

            printf("Please enter valid choice!");  

        }           

    }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 last_delete()  

{  

    struct node *ptr;  

    if(head == NULL)  

    {  

        printf("UNDERFLOW\n\n");  

    }  

    else if(head->next == NULL)  

    {  

        head = NULL;   

        free(head);  

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

    }  

    else   

    {  

        ptr = head;   

        if(ptr->next != NULL)  

        {  

            ptr = ptr -> next;   

        }  

        ptr -> prev -> next = NULL;   

        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

...