Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1-homework-yanjun
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bonnieyan
1-homework-yanjun
Commits
51370c36
Commit
51370c36
authored
Jan 15, 2019
by
bonnieyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第五次作业
parent
7542ca53
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
5-homework-yanjun/sort_utils.py
+7
-6
No files found.
5-homework-yanjun/sort_utils.py
View file @
51370c36
...
...
@@ -2,15 +2,15 @@ class SortUtils:
def
sort
(
self
,
f
,
s
):
if
f
==
"bubble"
:
for
i
in
range
(
len
(
s
)
-
1
):
for
j
in
range
(
len
(
s
)
-
i
-
1
):
for
j
in
range
(
len
(
s
)
-
i
-
1
):
if
s
[
j
]
>
s
[
j
+
1
]:
s
[
j
],
s
[
j
+
1
]
=
s
[
j
+
1
],
s
[
j
]
print
(
s
)
#print(s)
if
f
==
"quick"
:
SortUtils
.
__quick_sort
(
s
,
0
,
len
(
s
)
-
1
)
SortUtils
.
__quick_sort
(
s
elf
,
s
,
0
,
len
(
s
)
-
1
)
def
__quick_sort
(
sort_list
,
start_index
,
end_index
):
def
__quick_sort
(
s
elf
,
s
ort_list
,
start_index
,
end_index
):
# print(sort_list)
if
start_index
<
end_index
:
# 如果角标左侧小于右侧则开始排序,否则退出
basic
,
i
,
j
=
sort_list
[
start_index
],
start_index
,
end_index
...
...
@@ -26,10 +26,10 @@ class SortUtils:
print
(
"i="
+
str
(
i
)
+
"&&&"
+
"j="
+
str
(
j
)
+
"$$$"
+
"sort_list="
+
str
(
sort_list
))
sort_list
[
i
],
sort_list
[
start_index
]
=
sort_list
[
start_index
],
sort_list
[
i
]
SortUtils
.
__quick_sort
(
sort_list
,
start_index
,
i
-
1
)
SortUtils
.
__quick_sort
(
sort_list
,
i
+
1
,
end_index
)
SortUtils
.
__quick_sort
(
s
elf
,
s
ort_list
,
start_index
,
i
-
1
)
SortUtils
.
__quick_sort
(
s
elf
,
s
ort_list
,
i
+
1
,
end_index
)
p
=
SortUtils
()
p
.
sort
(
"bubble"
,
[
10
,
5
,
2
,
16
,
4
,
9
,
13
,
8
])
p
.
sort
(
"quick"
,
[
10
,
5
,
2
,
16
,
4
,
9
,
13
,
8
])
p
.
sort
(
"quick"
,
[
10
,
5
,
2
,
16
,
4
,
9
,
13
,
8
])
\ 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