Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson13-diy2
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
33b3d57a
authored
Sep 30, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
ce1e96e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
18 deletions
diy2.py
diy2.py
View file @
33b3d57a
alist
=
[
114514
,
114451
,
114451
,
141154
,
115414
,
115144
,
154114
,
114154
]
a
=
len
(
alist
)
for
k
in
range
(
a
-
1
):
for
i
in
range
(
a
-
k
-
1
):
if
alist
[
i
]
>
alist
[
i
+
1
]:
alist
[
i
],
alist
[
i
+
1
]
=
alist
[
i
+
1
],
alist
[
i
]
print
(
alist
)
#第一步:求出列表长度
#第二步:外层循环控制总共进行多少轮等于列表长度减一
#第三步:内层循环控制每一轮比较次数 第一轮长度减一 第二轮长度减二 第三轮长度减三......
#第四步:如果前面位置的值比后面位置的值大就交换位置(每次只能两两交换)
#第五步:从小到大排序
#alist[i],alist[i+1] = alist[i+1],alist[i]只能在python使用
#其他语言使用:
#t=alist[i]
#alist[i] = alist[i+1]
#alist[i+1] = t
\ 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