mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 13:31:07 +00:00
02c0daf9e5
* Adding variable to fade out ambiguity * More readability on merge sorting algorithm * Updating merge_sort_fastest description and explaining why * Adding tests file with imports * Standardazing filenames and function names * Adding test cases and test functions * Adding test loop * Putting 'user oriented code' inside main condition for having valid imports * Fixing condition * Updating tests: adding cases and todo list * Refactoring first euler problem's first solution
20 lines
613 B
Python
20 lines
613 B
Python
"""
|
|
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].
|
|
"""
|
|
def wiggle_sort(nums):
|
|
for i in range(len(nums)):
|
|
if (i % 2 == 1) == (nums[i-1] > nums[i]):
|
|
nums[i-1], nums[i] = nums[i], nums[i-1]
|
|
|
|
if __name__ == '__main__':
|
|
print("Enter the array elements:\n")
|
|
array=list(map(int,input().split()))
|
|
print("The unsorted array is:\n")
|
|
print(array)
|
|
wiggle_sort(array)
|
|
print("Array after Wiggle sort:\n")
|
|
print(array)
|