# Hackerrank Day 15 Linked List 30 days of code solution

In this HackerRank Day 15 Linked List 30 days of code problem Complete the insert function in your editor so that it creates a new Node (pass data as the Node constructor argument) and inserts it at the tail of the linked list referenced by the head parameter. Once the new node is added, return the reference to the head node.

## Problem solution in Python 2 programming.

```    def insert(self,head,data):
#Complete this method
node = Node(data)
else:
while current.next:
current = current.next
current.next = node

## Problem solution in Python 3 programming.

```    def insert(self,head,data):
temp = Node(data)
while current.next is not None:
current = current.next
current.next = temp
```

### Problem solution in java programming.

```    public static  Node insert(Node head,int data){
// if list has no elements, return a new node
return new Node(data);
}

// else iterate through list, add node to tail, and return head
while(tmp.next != null){
tmp = tmp.next;
}
tmp.next = new Node(data);

}```

### Problem solution in c++ programming.

```      Node* insert(Node *head,int data)
{
//Complete this method
return new Node(data);
}

while(temp->next != nullptr){
temp = temp->next;
}

temp->next = new Node(data);
}```

### Problem solution in c programming.

```Node* insert(Node *head,int data)
{
//Complete this function
struct Node *ll, *it;
ll=(struct Node *)malloc(sizeof(struct Node));
ll->data=data;
ll->next=NULL;

{
}
else
{
while(it->next)
it=it->next;
it->next=ll;
}
}```

### Problem solution in Javascript programming.

```    this.insert=function(head,data){
//complete this method
var newNode = new Node(data);

} else if (head.next === null) {
} else {