A PTC Creo feature-processing pipeline stores pending operations in a singly linked list. Reverse the list in place so the most recently added operation is processed first. Implement both iterative and recursive approaches, without creating replacement nodes.
Each node has an integer value and a next pointer that is either another node or None. Given the list head and a Boolean recursive, return the new head after reversing every link. When recursive is False, use an iterative algorithm. When it is True, use a recursive algorithm. The input list may be empty.
For evaluation, linked lists are represented by arrays of values. The expected result is the array obtained by traversing the returned head.
def reverse_linked_list(head, recursive=False):