英文:
How does std::sort_heap break the heap property?
问题
结果范围不再具有堆属性。
范围失去了作为堆的属性。
它们的意思是,排序后的范围不再满足堆的性质。
英文:
cppreference.com says:
> The resulting range no longer has the heap property.
cplusplus.com says:
> The range loses its properties as a heap.
What do they mean? It sorts, and sorted implies heap, no?
答案1
得分: 3
一个升序排序的列表自动成为最小堆。一个降序排序的列表自动成为最大堆。std::sort_heap
将一个最大堆转换为一个升序排序的列表,这不再是一个最大堆(但它是一个最小堆)。再强调一遍:关键点在于排序顺序被颠倒。列表从“弱降序”(最大堆)转变为升序(排序后,不再是最大堆)。
英文:
A list sorted ascending is automatically a min-heap. A list sorted descending is automatically a max-heap. std::sort_heap
turns a max heap into a list sorted ascending, which is no longer a max-heap (but it is a min-heap). To reiterate: the subtlety is that the ordering is being reversed. The list is turned from "weakly descending" (max-heap) to ascending (sorted, not a max-heap).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论