Better to add data or new node as parameter
I'm learning graphs and I am building a digraph via adjacent list, so I'm going to use an array of ptrs, so each index in array stores head ptr to a linked list of adjacente vertices where first node is the starting vertex to which all nodes in this indice are adjacent to.
Is it better to store pass the data and create new node inside function or better to create new node outside function and then pass that as parameter to my insert_to_end function:
Code:
void insert_at_end(int vertex)
{
LL newNode = new LL;
newNode.vertex = vertex;
newNode.next = this.array[this.size - 1];//point to whatever head in this index points to
this.array[this.size - 1] = newNode;
}
/**vs*/
void insert_at_end(LL newNode)//assuming it's created earlier
{
newNode.next = this.array[this.size - 1];//point to whatever head in this index points to
this.array[this.size - 1] = newNode;
}
Does it really matter in terms of good design?