Question

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 <stdio.h>
#include <stdlib.h>

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 < head -> 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 < New_node -> 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 < New_node ->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 Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
this is i have code for double linked list with insert at sorted list. i have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • BELOW IS THE CODE I ALREADY HAVE Linked List - Delete Modify Lab 5 and include...

    BELOW IS THE CODE I ALREADY HAVE Linked List - Delete Modify Lab 5 and include the method to delete a node from the Linked List. In summary: 1) Add the method Delete 2) Method call to delete, with a number that IS in the list 3) Method call to delete, with a number that is NOT in the list - Be sure to include comments - Use meaningful identifier names (constants where appropriate) import java.io.*; 1/ Java program to...

  • C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the...

    C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...

  • c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream>...

    c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream> using namespace std; template<class T> struct Node {     T data;//data field     Node * next;//link field     Node(T data) {       this->data = data;     } }; template<class T> class linked_list{ private:       Node<T> *head,*current; public:       linked_list(){//constructor, empty linked list         head = NULL;         current = NULL;       }       ~linked_list(){         current = head;         while(current != NULL) {          ...

  • Consider the following code to insert an item in a sorted linked list without a dummy...

    Consider the following code to insert an item in a sorted linked list without a dummy node. 60 public void insert(T t) { 61 Node p; 62 for (p = head; head != null; p = p.next) 63 if (p.data.compareTo(t) > 0) break; 64 if (p == head) p = new Node(t, head); 65 else p.next = new Node(t,p); 66 } If we insert the value 5 into an empty list, nothing happens. The list stays empty. Why did we...

  • Write a function to insert a name at the end of a linked list? (C) I...

    Write a function to insert a name at the end of a linked list? (C) I have a linked list: struct node { char person[100]; struct node *next; }; int main() { struct node *new_node; new_node=malloc(sizeof(struct node)); printf("Please enter a name:\n"); scanf("%s", ); } How do I get the name from the user and write a function to add it to the end of the linked list? I'm not supposed to use the insert() library function, which is why I'm...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a...

    ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful.  Also note that the function must work no matter how many nodes...

  • Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time...

    Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...

  • Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how...

    Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how to get size. I'm not sure. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null; prev = null; data = 0; } /* Constructor */ public Node(int d, Node n, Node p) { data = d; next = n; prev = p; } /* Function...

  • Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your...

    Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your name and the date. Describe the purpose of the code. Also, list each pointer and describe how it is used to enable the selection sort for the linked list structure. */ /* Insert code as described by the comments. */ /* Add comments to each line of code that uses a pointer, describing how it is being used. */ #include <iostream> using namespace std;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT