FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-1/sort/insertion_sort.py at master · githubch/algorithms-1 · GitHub
githubch
/
algorithms-1
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-1
/
sort
/
insertion_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
14 lines (14 loc) · 382 Bytes
Breadcrumbs
algorithms-1
/
sort
/
insertion_sort.py
Copy path
File metadata and controls
14 lines (14 loc) · 382 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
def
insertion_sort
(
arr
):
""" Insertion Sort
Complexity: O(n^2)
"""
for
i
in
xrange
(
len
(
arr
)):
cursor
=
arr
[
i
]
pos
=
i
while
pos
>
0
and
arr
[
pos
-
1
]
>
cursor
:
# Swap the number down the list
arr
[
pos
]
=
arr
[
pos
-
1
]
pos
=
pos
-
1
# Break and do the final swap
arr
[
pos
]
=
cursor
return
arr
Back
|
FazBrowse Home
|
New Git URL