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;
}
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.
this is i have code for double linked list with insert at sorted list. i have...
C++: I need implement this code using Double Linked List using the cosiderations 1. head point to null in an empty list 2. There is not need of a tail pointer /*This class implements the singly linked list using templates Each list has two attributes: -head: first node in the list -tail: last node in the list #include "circDLLNode.h" template class { public: //Default constructor: creates an empty list (); //Destructor: deallocate memory ~(); ...
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 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 LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...
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 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 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. 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 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...
C LINKED LIST #include <stdlib.h> #include <stdio.h> //Struct for a polynomial term (double linked list object) typedef struct Polynomial t_Polynomial; typedef struct Term { // coefficient of the polynomial term associated with the object int coef; // power of the polynomial term associated with the object int power; // pointer to the next object (to facilitate a doubly linked list) struct Term *next; // pointer to the previous object (to facilitate a doubly linked list) struct Term...