Write My Paper Button

WhatsApp Widget

this is i have code for double linked list with insert at sorted list. i have…

Homework Help Question & Answers

this is i have code for double linked list with insert at sorted list. i have…

this is i have code for double linked list with insert at sorted list. i have some error that

stdout: ------- Error: compilation  stderr: ------- InsertDouble.c: In function ‘list* InsertDouble(LIST, int)’: InsertDouble.c:51:14: error: cannot convert ‘list’ to ‘list*’ in assignment    Currentptr = *head;        // set a pointer which is current one               ^ 

it keep give me this error i am not sure how to fix is anyone possible to help me?

#include
#include

typedef struct list {
   struct list* next;
   struct list* prev;
   int val;
} *LIST;

//   DO NOT MODIFY ABOVE THIS LINE

//   MODIFY THIS FUNCTION
//
//   Given a pointer to the head of the list. Insert x in its correct sorted place.
//   For example, if the list is [ 1 4 9 12 ], and x is 10, then the list
//       should look like [ 1 4 9 10 12 ] after insertion.

LIST InsertDouble(LIST head, int x) {
  
LIST New_node = (LIST)malloc(sizeof(struct list));  
  
struct list *Currentptr = NULL;
  
New_node -> next = NULL;                               // make new node pointer to null
  
New_node ->val = x;                                   // make new node value set at x
  
if(New_node == NULL){                                   // if new node have no x value it terminate
  
printf(“No exist memory”);
    return 0;
}
// add at front of list
if (head == NULL){
  
head = New_node;
  
}
  
//if x is less then first node of list
else if(New_node->val val ){
  
   New_node -> next = head;
  
head = New_node;
  
}
  
// make pointer for head so i can make move around
Currentptr = *head;                               // set a pointer which is current one
//to save New_node to end of the list
while(Currentptr != NULL){
  
if(Currentptr-> next == NULL){
  
Currentptr->next = New_node;
  
}
else if(Currentptr ->val val){
  
    New_node -> next = Currentptr -> next;
  
   Currentptr ->next = New_node;
  
   New_node->prev = Currentptr;
  
   Currentptr ->next ->next = New_node;
  
  
}
  
Currentptr = Currentptr->next;
}
  
  
/*
while (head != NULL){
if(Currentptr ->next == NULL && Currentptr -> val val){
  
New_node -> prev = Currentptr;
  
Currentptr -> next = New_node;
  
}
else if(Currentptr -> next != NULL && New_node ->val > Currentptr -> val){
  
  
}
  
Currentptr = Currentptr -> next;
  
}
  
*/
return head;
  
}
  

0 0
Add a comment
Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?