mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 18:49:26 +08:00
Added Whitespace and Docstring (#924)
* Added Whitespace and Docstring I modified the file to make Pylint happier and make the code more readable. * Beautified Code and Added Docstring I modified the file to make Pylint happier and make the code more readable. * Added DOCSTRINGS, Wikipedia link, and whitespace I added DOCSTRINGS and whitespace to make the code more readable and understandable. * Improved Formatting * Wrapped comments * Fixed spelling error for `movement` variable * Added DOCSTRINGs * Improved Formatting * Corrected whitespace to improve readability. * Added docstrings. * Made comments fit inside an 80 column layout.
This commit is contained in:
@ -1,17 +1,24 @@
|
||||
"""
|
||||
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
|
||||
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]
|
||||
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):
|
||||
"""Perform Wiggle Sort."""
|
||||
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 (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()))
|
||||
array = list(map(int, input().split()))
|
||||
print("The unsorted array is:\n")
|
||||
print(array)
|
||||
wiggle_sort(array)
|
||||
|
Reference in New Issue
Block a user