Insert a node at the head of a linked list

Sort by

recency

|

982 Discussions

|

  • + 0 comments

    Just a warning to anyone writing this in C# c sharp: there is an error in the main function that makes solving this problem using C# impossible.

    PrintSinglyLinkedList(llist->head, "\n", textWriter);

    should be

    PrintSinglyLinkedList(llist.head, "\n", textWriter);

  • + 0 comments

    Here is my c++ solution you watch vide explanation here : https://youtu.be/COnfpdhOlN8

    SinglyLinkedListNode* insertNodeAtHead(SinglyLinkedListNode* llist, int data) {
       SinglyLinkedListNode* new_node = new SinglyLinkedListNode(data);
       new_node -> next = llist;
       return new_node;
    }
    
  • + 0 comments

    here's my solution in C language:

    SinglyLinkedListNode* insertNodeAtHead(SinglyLinkedListNode* llist, int data) { SinglyLinkedListNode* node = malloc(sizeof(SinglyLinkedListNode)); node->data = data; node->next = llist; llist = node; return llist; }

  • + 0 comments

    It must be something wrong with the task. The constrains says that the lsit is not null and data is not null. So I made a simple code:

         SinglyLinkedListNode node =new SinglyLinkedListNode(data);
         node.next=llist;
         return node; 
    
                 But I run in a bunch of nullable errors. 
                 Also the explanation looks like an explanation from some other task.
    
  • + 0 comments

    They’re crucial for optimizing performance, especially when handling large volumes of data. ekbet11.com login