Skip to content

Commit d09c2f1

Browse files
committed
add partition testcase
1 parent ea7e803 commit d09c2f1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

docs/13_高级排序算法/quick_sort.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ T(n) = 2T(n/2) + n
128128

129129
# Leetcode
130130

131+
无序数组寻找第 k 大的数字。
131132
https://leetcode.com/problems/kth-largest-element-in-an-array/description/

docs/13_高级排序算法/quicksort.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def test_partition():
5757
assert partition(l, 0, len(l)) == 0
5858
l = [4, 3, 2, 1]
5959
assert partition(l, 0, len(l)) == 3
60+
l = [1]
61+
assert partition(l, 0, len(l)) == 0
62+
l = [2,1]
63+
assert partition(l, 0, len(l)) == 1
6064

6165

6266
def test_quicksort_inplace():
@@ -91,6 +95,9 @@ def test_nth_element():
9195
for i in reversed(l):
9296
assert nth_element(l, 0, len(l), i) == i
9397

98+
array = [3, 2, 1, 5, 6, 4]
99+
assert nth_element(array, 0, len(array), 2) == 2
100+
94101

95102
if __name__ == '__main__':
96103
test_nth_element()

0 commit comments

Comments
 (0)