Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson13-diy1
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
240991cb
authored
Jul 16, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
92449b0c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
5 deletions
diy1.py
diy1.py
View file @
240991cb
list1
=
[]
# import time
for
a
in
range
(
0
,
1000
):
# start = time.time()
for
b
in
range
(
0
,
1000
):
list1
.
insert
(
0
,
0
)
# #保证总次数是100万次
\ No newline at end of file
# list1 = []
# for a in range(0, 1000):
# for b in range(0, 1000):
# list1.append(0)
# #在列表索引为0的位置处添加一个数据0
# #append(数据)在列表的末尾添加数据
# #extend(列表类型的数据)将两个列表合并成一个列表
# end = time.time()
# print(end-start)
# '''
# 结束时间 - 开始时间 = 运行时间
# time.time()可以用来计算结束时间和开始时间,放到开头计算开始时间 放到结尾就是计算结束时间
# '''
#冒泡排序的模板
alist
=
[
1
,
5
,
2
,
5441
,
64
,
4
,
44
,
8
,
4568
,
458
]
#1.求列表长度赋值给一个变量
n
=
len
(
alist
)
#2.构建外层循环,代表的循环的轮数 循环列表长度-1
for
i
in
range
(
n
-
1
):
#3.构建内层循环,代表比较的次数 列表长度-1-i 内层循环变量作为索引表示的列表中的数值就是当前的气泡
for
j
in
range
(
n
-
i
-
1
):
#4.如果当前的数据大,则进行交换
if
alist
[
j
]
>
alist
[
j
+
1
]:
alist
[
j
],
alist
[
j
+
1
]
=
alist
[
j
+
1
],
alist
[
j
]
#5.输出列表
print
(
alist
)
\ No newline at end of file
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