zoukankan      html  css  js  c++  java
  • 优先队列(Priority Queue)

    【最大堆实现优先队列】

    用最大堆来实现优先队列,每一次入队操作就是堆的插入操作,每一次出队操作就是删除堆顶节点。

    【入队操作】

    1、插入新节点5:

    2、新节点5上浮到合适位置:

    【出队操作】

    1、把原堆顶节点10“出队”:

    2、最后一个节点1替换到堆顶位置:

    3、节点1下沉,节点9成为新堆顶:


    优先队列(Priority Queue

    A priority queue must at least support the following operations:

    • insert_with_priority: add an element to the queue with an associated priority.
    • pull_highest_priority_element: remove the element from the queue that has the highest priority, and return it.
      This is also known as "pop_element(Off)", "get_maximum_element" or "get_front(most)_element".
      Some conventions reverse the order of priorities, considering lower values to be higher priority, so this may also be known as "get_minimum_element", and is often referred to as "get-min" in the literature.
      This may instead be specified as separate "peek_at_highest_priority_element" and "delete_element" functions, which can be combined to produce "pull_highest_priority_element".

    In addition, peek (in this context often called find-max or find-min), which returns the highest-priority element but does not modify the queue, is very frequently implemented, and nearly always executes in O(1) time. This operation and its O(1) performance is crucial to many applications of priority queues.

    More advanced implementations may support more complicated operations, such as pull_lowest_priority_element, inspecting the first few highest- or lowest-priority elements, clearing the queue, clearing subsets of the queue, performing a batch insert, merging two or more queues into one, incrementing priority of any element, etc.


    参考引用:

    https://www.sohu.com/a/256022793_478315

  • 相关阅读:
    xml学习笔记2
    用SVN下载sourceforge上的源代码
    析构函数的浅谈《原创》
    论程序员与妓女
    简单的动画
    突然收到Steve Harmon的短消息,真意外啊。
    从长春到北京--“一个人的旅行”
    动画停止和延时
    。NET :遍历某个权限集中的权限列表
    如何让Silverlight程序可以在浏览器外运行
  • 原文地址:https://www.cnblogs.com/utank/p/4285355.html
Copyright © 2011-2022 走看看