Merged the functions freeLinkedList and freeLinkedListShallow into a single function