Skip to content

Commit

Permalink
fix algo demo1
Browse files Browse the repository at this point in the history
  • Loading branch information
mgss committed Oct 29, 2017
1 parent 05e3bcd commit 452c4ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion docs/algo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Demo-1

*
* 冒泡排序

参考Demo:[链接](https://github.com/mgss/python-demo/blob/master/example/algo/demo1.py)

## Demo-2

* 递归

参考Demo:[链接](https://github.com/mgss/python-demo/blob/master/example/algo/demo2.py)
24 changes: 23 additions & 1 deletion example/algo/demo1.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-


li = [11, 1, 1, 1, 1, 2, 35, 7, 34, 8, 1, 123, 23, 34, 511, 213, 34, 56, 0]


# 冒泡排序
def bubbling(arr):
new_list = list(arr)

for i in range(1, len(new_list)):
for j in range(len(new_list) - i):

if new_list[j] > new_list[j + 1]:
temp = new_list[j]
new_list[j] = new_list[j + 1]
new_list[j + 1] = temp

return new_list


new = bubbling(li)
print(new)

0 comments on commit 452c4ac

Please sign in to comment.