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

时间堆del_函数 #85

Open
kkndme-wx opened this issue Jun 5, 2023 · 2 comments
Open

时间堆del_函数 #85

kkndme-wx opened this issue Jun 5, 2023 · 2 comments

Comments

@kkndme-wx
Copy link

void HeapTimer::del_(size_t index) {
/* 删除指定位置的结点 /
assert(!heap_.empty() && index >= 0 && index < heap_.size());
/
将要删除的结点换到队尾,然后调整堆 */
size_t i = index;
size_t n = heap_.size() - 1;
assert(i <= n);
if(i < n) {
SwapNode_(i, n);
if(!siftdown_(i, n)) {
siftup_(i);
}
}
这里的siftdown_(i,n)是否应该是siftdown(i,n-1)?

@kkndme-wx kkndme-wx reopened this Jun 5, 2023
@lizyzzz
Copy link

lizyzzz commented Jun 24, 2023

这里没有错,n已经是size() - 1了

@peng-yq
Copy link

peng-yq commented May 8, 2024

void HeapTimer::del_(size_t index) { /* 删除指定位置的结点 / assert(!heap.empty() && index >= 0 && index < heap_.size()); /_ 将要删除的结点换到队尾,然后调整堆 */ size_t i = index; size_t n = heap_.size() - 1; assert(i <= n); if(i < n) { SwapNode_(i, n); if(!siftdown_(i, n)) { siftup_(i); } } 这里的siftdown_(i,n)是否应该是siftdown(i,n-1)?

没有问题,因为n=size()-1,并且siftdown中while循环的条件为j<n

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

3 participants