FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/sort/wiggle_sort.py at master · ivan1911/algorithms-python · GitHub
ivan1911
/
algorithms-python
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms-python
/
algorithms
/
sort
/
wiggle_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
16 lines (12 loc) · 376 Bytes
Breadcrumbs
algorithms-python
/
algorithms
/
sort
/
wiggle_sort.py
Copy path
File metadata and controls
16 lines (12 loc) · 376 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
"""
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__"
:
array
=
[
3
,
5
,
2
,
1
,
6
,
4
]
print
(
array
)
wiggle_sort
(
array
)
print
(
array
)
Back
|
FazBrowse Home
|
New Git URL