Insert function to insert new nodes at the end.