Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.5优先队列勘误 #73

Closed
PhoenixChen98 opened this issue May 23, 2022 · 1 comment
Closed

11.5优先队列勘误 #73

PhoenixChen98 opened this issue May 23, 2022 · 1 comment

Comments

@PhoenixChen98
Copy link

PhoenixChen98 commented May 23, 2022

首先非常感谢笔记的整理!对我帮助很大!
在书中11.5优先队列一节,用数组表示堆时,应该将0号位空着,即top函数应返回heap[1],pop时也应该将末尾元素放入heap[1],然后sink(1)
您可以运行下您这一节中的代码测试一下,我这边的测试结果如下:

q.push(2);
q.push(3);
cout << q.top() << endl;//输出2
q.push(1);
cout << q.top() << endl;//输出2
q.push(4);
cout << q.top() << endl;//输出2
q.pop();//程序崩溃
cout << q.top() << endl;

此外,top函数的返回类型应该是int,而非void

@changgyhub
Copy link
Owner

感谢!下个版本即更正。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants