Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson1_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7b9e1f6a
authored
Aug 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
d85c24b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
a.py
abc.py
b.py
a.py
0 → 100644
View file @
7b9e1f6a
a
=
[
55
,
23
,
87
,
62
,
16
]
for
i
in
range
(
len
(
a
)
-
1
):
for
j
in
range
(
i
+
1
,
len
(
a
)):
if
a
[
i
]
<
a
[
j
]:
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
print
(
a
)
print
(
a
)
\ No newline at end of file
abc.py
0 → 100644
View file @
7b9e1f6a
array
=
[
2
,
3
,
5
,
7
,
1
,
4
,
6
,
15
,
5
,
2
,
7
,
9
,
10
,
15
,
9
,
17
,
12
]
def
qs
(
list
):
# 创建快速排序函数,传参列表
if
len
(
list
)
<
2
:
# 如果列表长度小于2
return
list
# 返回值就是列表本身
else
:
mid
=
int
(
len
(
list
)
/
5
)
print
(
'mid:'
,
mid
)
guess
=
list
[
mid
]
left
=
[]
right
=
[]
# left,right=[],[]
list
.
remove
(
guess
)
for
i
in
list
:
if
i
>=
guess
:
right
.
append
(
i
)
else
:
left
.
append
(
i
)
print
(
left
)
print
(
guess
)
print
(
right
)
return
qs
(
left
)
+
[
guess
]
+
qs
(
right
)
print
(
qs
(
array
))
# 创建快速排序函数,传参列表
# 如果列表长度小于2
# 返回值就是列表本身
# 否则
# 确定索引(可以是最低索引,中间索引,最高索引)
# 获取对应索引的值,作为基准值
# 创建左列表和右列表
# 将列表中的基准值删除
# 对列表进行遍历
# 如果遍历的值大于等于基准值
# 添加到右列表中
# 否则 (也就是小于基准值)
# 添加到左列表中
# 返回值 调用自身函数对左列表,拼接列表格式的基准值,拼接调用自身函数对右列表
# 调用函数对具体列表进行打印
\ No newline at end of file
b.py
0 → 100644
View file @
7b9e1f6a
import
random
list
=
[]
for
i
in
range
(
10
):
list
.
append
(
random
.
randint
(
1
,
100
))
print
(
list
)
print
()
for
i
in
range
(
len
(
list
)
-
1
):
index
=
i
for
j
in
range
(
i
+
1
,
len
(
list
)):
if
list
[
index
]
>
list
[
j
]:
index
=
j
list
[
i
],
list
[
index
]
=
list
[
index
],
list
[
i
]
print
(
list
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment