0 out of 464 challenges solved
Write a Python function `heap_sort` that takes a list of integers as input and returns a new list with the integers sorted in ascending order. Use the heap data structure to implement the sorting algorithm. #### Example Usage ```python [main.nopy] print(heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])) # Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(heap_sort([25, 35, 22, 85, 14, 65, 75, 25, 58])) # Output: [14, 22, 25, 25, 35, 58, 65, 75, 85] print(heap_sort([7, 1, 9, 5])) # Output: [1, 5, 7, 9] ``` #### Constraints - The input list will contain only integers. - The function should not modify the original list. - The function should use the heap data structure for sorting.
import heapq as hq def heap_sort(iterable): """ Sorts a list of integers using the heap sort algorithm. Args: iterable (list): A list of integers to be sorted. Returns: list: A new list containing the sorted integers. """ # Placeholder for the solution pass