sorts.wiggle_sort¶
Wiggle Sort.
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]…. For example: if input numbers = [3, 5, 2, 1, 6, 4] one possible Wiggle Sorted answer is [3, 5, 1, 6, 2, 4].
Attributes¶
Functions¶
|
Python implementation of wiggle sort. |
Module Contents¶
- sorts.wiggle_sort.wiggle_sort(nums: list) list¶
Python implementation of wiggle sort. Reorders an array such that nums[0] <= nums[1] >= nums[2] <= nums[3]…
Example: >>> wiggle_sort([0, 5, 3, 2, 2]) [0, 5, 2, 3, 2] >>> wiggle_sort([]) [] >>> wiggle_sort([-2, -5, -45]) [-5, -2, -45] >>> wiggle_sort([-2.1, -5.68, -45.11]) [-5.68, -2.1, -45.11]
- sorts.wiggle_sort.array¶