data_structures.arrays.reverse_array ==================================== .. py:module:: data_structures.arrays.reverse_array .. autoapi-nested-parse:: In-place array reversal that also returns the reversed list to the caller. This algorithm reverses the elements of a list without using extra space. Attributes ---------- .. autoapisummary:: data_structures.arrays.reverse_array.sample_array Functions --------- .. autoapisummary:: data_structures.arrays.reverse_array.reverse_array Module Contents --------------- .. py:function:: reverse_array(arr: list[Any]) -> list[Any] Reverses a list in-place. This function takes a list and reverses its elements using a two-pointer approach. The left pointer starts at the beginning of the list, and the right pointer starts at the end. The elements at these two pointers are swapped, and the pointers move towards the center until they meet or cross. Args: arr: The list to be reversed. Returns: The same list, now reversed. This allows for method chaining. Doctests: >>> reverse_array([1, 2, 3, 4, 5]) [5, 4, 3, 2, 1] >>> reverse_array(['a', 'b', 'c', 'd']) ['d', 'c', 'b', 'a'] >>> reverse_array([10.5, 20.2, 30.8]) [30.8, 20.2, 10.5] >>> reverse_array(["apple", "banana", "cherry"]) ['cherry', 'banana', 'apple'] >>> reverse_array([1]) [1] >>> reverse_array([]) [] >>> reverse_array(list(range(5))) [4, 3, 2, 1, 0] >>> reverse_array(tuple(range(5))) Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment >>> reverse_array(range(5)) Traceback (most recent call last): ... TypeError: 'range' object does not support item assignment .. py:data:: sample_array :value: [10, 20, 30, 40, 50, 60]