MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / wiggle_sort

Function wiggle_sort

sorts/wiggle_sort.py:7–10  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

5one possible Wiggle Sorted answer is [3, 5, 1, 6, 2, 4].
6"""
7def wiggle_sort(nums):
8 for i in range(len(nums)):
9 if (i % 2 == 1) == (nums[i-1] > nums[i]):
10 nums[i-1], nums[i] = nums[i], nums[i-1]
11
12
13print("Enter the array elements:\n")

Callers 1

wiggle_sort.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected