Insert a node at the head of a linked list

Sort by

recency

|

989 Discussions

|

  • + 0 comments

    Microservices Interview questions and answers

  • + 0 comments

    On the C# variant you have an error in line 83 that prevents code to be evaluated. PrintSinglyLinkedList(llist->head, "\n", textWriter); I think it should be: PrintSinglyLinkedList(llist_head, "\n", textWriter); Not all the time java code works in C# :D

  • + 0 comments

    Java Solution we want to insert the node head of the sll(sll Node,int data) { sll new head= new sllNode(data); if(list!=NULL) { Node.next=list return new head }

  • + 0 comments

    Java Solution we want to insert the node head of the sll(sll Node,int data) { sll new head= new sllNode(data); if(list!=NULL) { Node.next=list return new head }

  • + 0 comments

    My Java solution with o(1) time complexity and o(1) space complexity:

    static SinglyLinkedListNode insertNodeAtHead(SinglyLinkedListNode llist, int data) {
            SinglyLinkedListNode newHead = new SinglyLinkedListNode(data);
            newHead.next = llist;
            return newHead;
        }