We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Insert a node at the head of a linked list
Insert a node at the head of a linked list
+ 0 comments c# compilation is not working. the same code in java works fine.
+ 0 comments def insertNodeAtHead(llist, data): # Write your code here new_node = SinglyLinkedListNode(data) if not llist: return new_node new_node.next = llist return new_node
+ 0 comments Java 8 Solution:
static SinglyLinkedListNode insertNodeAtHead(SinglyLinkedListNode llist, int data) { SinglyLinkedListNode newNode = new SinglyLinkedListNode(data); if(llist != null) newNode.next = llist; llist = newNode; return llist; }
+ 0 comments Great stuff, i am very imppressed with your amazing work, now could you please have a look on my site and let me know how can i use this code on my site please?>
+ 0 comments little bit confusing for beginner I have face the same issue but dont' worry guys take a time and understand the whole code you will know how to work. for me i do not understand what's happing in llist and why tail is create but after read line by line. I have understood the code and end of that. I have solve the problem.
this is my c++ solution :
SinglyLinkedListNode* insertNodeAtHead(SinglyLinkedListNode* llist, int data) {
SinglyLinkedListNode* newNode = new SinglyLinkedListNode(data); if(llist == nullptr){ llist = newNode; } else{ newNode->next = llist; llist = newNode; } return llist;
}
Load more conversations
Sort 862 Discussions, By:
Please Login in order to post a comment