Skip to content

Commit d18d5ea

Browse files
committed
array_queue fix
1 parent 57c1281 commit d18d5ea

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
本教程是付费教程(文字内容和代码免费),因为笔者录制的过程中除了购买软件、手写板等硬件之外,业余需要花费很多时间和精力来录制视频、查资料、编写课件和代码,养家糊口不容易,希望大家体谅。
77

88
## 链接
9+
视频教程已经发布在网易云课堂和 csdn 学院,内容一致。
910

1011
[网易云课堂: Python数据结构与算法教程](http://study.163.com/course/introduction.htm?courseId=1005526003) 视频教程
1112

13+
[csdn 学院:Python数据结构与算法教程](https://edu.csdn.net/course/detail/8332)
14+
1215
[网上阅读《Python 算法与数据结构教程 》](http://ningning.today/python_data_structures_and_algorithms/)
1316

1417
[github 链接](https://github.com/PegasusWang/python_data_structures_and_algorithms)
@@ -180,7 +183,7 @@ Python 抽象程度比较高, 我们能用更少的代码来实现功能,同
180183
有出版社找过笔者想让我出书,一来自己对出书兴趣不大,另外感觉书籍相对视频不够直观,有错误也不能及时修改,打算直接把所有
181184
文字内容讲义和代码等放到 github 上,供大家免费查阅。
182185

183-
如果你发现文字内容、代码内容或者视频内容有错误,欢迎在 github 上提 issue 讨论,或者直接提 Merge Request,我会修正相关内容,防止对读者产生误导(同时感谢认真学习并及时发现书中错误的同学)。
186+
如果你发现文字内容、代码内容或者视频内容有错误,欢迎在 github 上提 issue 讨论,或者直接提 Merge Request,我会修正相关内容,防止对读者产生误导(同时非常感谢认真学习并及时发现书中错误的同学)。
184187

185188

186189
## 本电子书制作和写作方式

docs/04_队列/array_queue.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, maxsize):
4040
def push(self, value):
4141
if len(self) >= self.maxsize:
4242
raise FullError('queue full')
43-
self.array[self.head] = value
43+
self.array[self.head % self.maxsize] = value
4444
self.head += 1
4545

4646
def pop(self):
@@ -49,7 +49,7 @@ def pop(self):
4949
return value
5050

5151
def __len__(self):
52-
return self.head-self.tail
52+
return self.head - self.tail
5353

5454

5555
def test_queue():
@@ -68,10 +68,13 @@ def test_queue():
6868
assert q.pop() == 0
6969
assert q.pop() == 1
7070

71-
assert len(q) == 3
71+
q.push(5)
72+
73+
assert len(q) == 4
7274

7375
assert q.pop() == 2
7476
assert q.pop() == 3
7577
assert q.pop() == 4
78+
assert q.pop() == 5
7679

7780
assert len(q) == 0

0 commit comments

Comments
 (0)