Insert a node at the head of a linked list

  • + 1 comment

    Heres a really simple and clear code in python

    def insertNodeAtHead(head, data):
        temp = SinglyLinkedListNode(data)
        if not head:
            return temp
        else:
            temp.next = head
            head = temp
            return head