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

1 Answer

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

Deletion at beginning in Doubly Linked List

deletion at beginning in doubly linkedlist

Algorithm

WRITE UNDERFLOW
GOTO STEP 6

  • STEP 1: IF HEAD = NULL

  • STEP 2: SET PTR = HEAD

  • STEP 3: SET HEAD = HEAD → NEXT

  • STEP 4: SET HEAD → PREV = NULL

  • STEP 5: FREE PTR

  • STEP 6: EXIT

Program Code

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

void create(int);

void beginning_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 beginning\n3.Exit\nEnter your choice: ");

scanf("%d",&choice);

switch(choice)

{

case 1:

printf("Enter the item: ");

scanf("%d",&item);

create(item);

break;

case 2:

beginning_delete();

break;

case 3:

exit(0);

break;

default:

printf("\nPlease enter valid choice!\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 beginning_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;

head = head -> next;

head -> prev = 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

...