Linked list

Programming
Tutor: None Selected Time limit: 3 Days

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;
     }

   }
}

Oct 12th, 2013
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
Oct 12th, 2013

Are you studying on the go? Check out our FREE app and post questions on the fly!
Download on the
App Store
...
Oct 12th, 2013
...
Oct 12th, 2013
Dec 6th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer