public static Node insert(Node head, int data) {
Node newNode = new Node(data);
if(head == null) {
return newNode;
}
Node node = head;
while(node.next != null) {
node = node.next;
}
node.next = newNode;
return head;
}
function insert($head, $data) {
$newNode = new Node($data);
if(is_null($head)) {
return $newNode;
}
$node = $head;
while(!is_null($node->next)) {
$node = $node->next;
}
$node->next = $newNode;
return $head;
}
def insert(self,head,data):
#Complete this method
newNode = Node(data)
if head is None:
return newNode
node = head
while node.next is not None:
node = node.next
node.next = newNode
return head