Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Returning the head in a function that adds a node to the end of a linked list allows us to easily access the updated list outside of the function. Since the head of the list is the starting point, returning it enables us to traverse the entire list from beginning to end.

In arrays, adding an element to the end does not require returning the entire array because arrays are stored in contiguous memory blocks. Therefore, we can simply modify the value at the next available index and update the array length variable. We can access the updated array outside of the function using the array variable.