FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/algorithms/sort/shell_sort.py at master · pk210700/algorithms · GitHub
pk210700
algorithms
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
algorithms
/
sort
/
shell_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (19 loc) · 542 Bytes
Breadcrumbs
algorithms
/
algorithms
/
sort
/
shell_sort.py
Copy path
File metadata and controls
21 lines (19 loc) · 542 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
15
16
17
18
19
20
21
def
shell_sort
(
arr
):
''' Shell Sort
Complexity: O(n^2)
'''
n
=
len
(
arr
)
# Initialize size of the gap
gap
=
n
//
2
while
gap
>
0
:
y_index
=
gap
while
y_index
<
len
(
arr
):
y
=
arr
[
y_index
]
x_index
=
y_index
-
gap
while
x_index
>=
0
and
y
<
arr
[
x_index
]:
arr
[
x_index
+
gap
]
=
arr
[
x_index
]
x_index
=
x_index
-
gap
arr
[
x_index
+
gap
]
=
y
y_index
=
y_index
+
1
gap
=
gap
//
2
return
arr
Back
|
FazBrowse Home
|
New Git URL