GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add insertionSort in python (#808) · rabbitqyh/leetcode@0438945

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • basic/sorting/InsertionSort
    • InsertionSort.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎basic/sorting/InsertionSort/InsertionSort.py‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def insertion_sort(array):
2+
for i in range(len(array)):
3+
cur_index = i
4+
while array[cur_index - 1] > array[cur_index] and cur_index - 1 >= 0:
5+
array[cur_index], array[cur_index - 1] = array[cur_index - 1], array[cur_index]
6+
cur_index -= 1
7+
return array
8+
9+
array = [10, 17, 50, 7, 30, 24, 27, 45, 15, 5, 36, 21]
10+
print(insertion_sort(array))

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.