Programming
Linked list

Question Description

What is the error in following code for doubly linked list?

#include<stdio.h>
#include<stdlib.h>
struct node
{
   int data;
   struct node* next;
   struct node* prev;
};
void add_node(struct node* ptr);
void delete_node(struct node* ptr);
void display_list(struct node* ptr);
int main()
{
   struct node* head=NULL;
   int choice;
   again:
   printf("\n1) Add node");
   printf("\n2) Delete node");
   printf("\n3) Display list");
   printf("\n4) Exit");
   printf("\nEnter choice : ");
   scanf("%d",&choice);
   switch(choice)
   {
     case 1:
       add_node(head);break;
     case 2:
       delete_node(head);break;
     case 3:
       display_list(head);break;
     case 4:
       exit(0);
     default:
       goto again;
   }
   printf("Do you want to continue : ");
   scanf("%d",&choice);
   if(choice=='y'||choice=='Y')
     goto again;
   else
     exit(0);
   return 0;
}
void add_node(struct node* ptr)
{
   struct node* temp=(struct node*)malloc(sizeof(struct node));
   if(ptr==NULL)
   {
     ptr->next=temp;
     ptr->prev=NULL;
   }
   else
   {
     temp->next=ptr->next;
     ptr->next=temp;
   }
   display_list(ptr);
}

void delete_node(struct node* ptr)
{
   struct node* temp=NULL;
   if(ptr->next==NULL)
   {
     printf("\nUnderflow : No node present");
     exit(0);
   }
   else
   {
     temp=ptr->next;
     temp=temp->next;
     ptr=temp;
   }
   display_list(ptr);
}

void display_list(struct node* ptr)
{
   struct node* temp,*start=ptr;
   if(ptr->next==NULL)
   {
     printf("%d---->>>>",ptr->data);
   }
   else
   {
     while(start->next!=NULL)
     {
       printf("%d---->>>>----",start->data);
       temp=start->next;
       start=temp;
     }

   }
}

Final Answer

i have done a lot of good work for some users with a website called studentoffortune with an earnings of $13,848 and 533A+ rating,i assure u wont be down with my work. hope for a positive response

fornicola (20)
UC Berkeley

Anonymous
Top quality work from this tutor! I’ll be back!

Anonymous
It’s my second time using SP and the work has been great back to back :) The one and only resource on the Interwebs for the work that needs to be done!

Anonymous
Thanks, good work

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors