Skip to content

Commit 7d698e4

Browse files
dyhdyh
authored andcommitted
修改
1 parent 1f9e66c commit 7d698e4

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
python/.idea
3+
python/.DS_Store

python/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python/.idea
2+
.DS_Store
3+
python/.DS_Store
4+
.idea

python/array/__init__.py

Whitespace-only changes.

python/array/test.py

Whitespace-only changes.

python/sort/bubble_sort.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def bubble_sort(arr):
3+
n = len(arr)
4+
for i in range(n):
5+
for j in range(0, n-i-1):
6+
if arr[j] > arr[j+1]:
7+
temp = arr[j]
8+
arr[j] = arr[j+1]
9+
arr[j+1] = temp
10+
return arr
11+
12+
13+
14+
if __name__ == '__main__':
15+
arr = [4,8,9,6,7,2]
16+
res = bubble_sort(arr)
17+
print(res)

python/sort/insert_sort.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def insert_sort(arr):
3+
n = len(arr)
4+
for i in range(1, n):
5+
key = arr[i]
6+
j = i - 1
7+
while j >= 0 and arr[j] > key:
8+
arr[j + 1] = arr[j]
9+
j -= 1
10+
arr[j + 1] = key
11+
return arr
12+
13+
if __name__ == '__main__':
14+
arr = [3,2,1,7,0,4,5]
15+
res = insert_sort(arr)
16+
17+
print(res)

0 commit comments

Comments
 (0)