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

  • 相关阅读:
    $this是什么意思-成员变量和局部变量的调用
    神经网络 ML08 c-d-e
    机器学习笔记 ML01c
    虚函数
    C++有哪几种情况只能用初始化列表,而不能用赋值?
    C++ 的 I/O
    引用
    宏定义 #define 和常量 const 的区别
    怎么设置才能让外网ip可以访问mysql数据库[转]
    大师的框架面试总结[转]
  • 原文地址:https://www.cnblogs.com/utank/p/4285355.html
Copyright © 2011-2022 走看看