当前位置: 首页 > news >正文

用vue-cli做的网站潍坊seo培训

用vue-cli做的网站,潍坊seo培训,深圳龙岗有什么好玩的地方,温州网站建设服务文章目录 C 优先级队列用法与模拟实现介绍用法头文件1.创建优先级队列priority_queue 2. 插入元素push 3. 删除元素pop 访问顶部元素top 检查优先级队列的大小size 检查优先级队列是否为空empty 模拟实现 C 优先级队列用法与模拟实现 介绍 优先级队列(Priority Qu…

文章目录

  • C++ 优先级队列用法与模拟实现
    • 介绍
    • 用法
      • 头文件
      • 1.创建优先级队列
        • priority_queue
      • 2. 插入元素
        • push
      • 3. 删除元素
        • pop
      • 访问顶部元素
        • top
      • 检查优先级队列的大小
        • size
      • 检查优先级队列是否为空
        • empty
    • 模拟实现

C++ 优先级队列用法与模拟实现

介绍

优先级队列(Priority Queue)是一种抽象数据类型,它类似于队列,但是每个元素都有一个优先级或权重。在优先级队列中,元素的出队顺序是按照优先级来进行的,而不是先进先出(FIFO)或后进先出(LIFO)。
在 C++ 中,优先级队列是通过 std::priority_queue 实现的,它是 C++ 标准库的一部分。std::priority_queue 是一个模板容器适配器,它提供常数时间复杂度的插入操作和 logarithmic 时间复杂度的删除操作。

用法

头文件

要使用 std::priority_queue,你需要包含 <queue> 头文件。

#include <queue>

1.创建优先级队列

在这里插入图片描述

priority_queue
  • (1)
    构造函数,可以接受两个参数,一个比较函数和一个容器。是个显式构造,不用隐式类型转换。
  • (2)
    接受两个迭代器的构造函数,它允许你从一个范围 [first, last) 中的元素初始化优先级队列
//(1)
priority_queue<int> pq1; // 创建一个整数类型的优先级队列
priority_queue<int, vector<int>, less<int>> pq2;//创建一个以vector作为底层容器类型的优先级队列,less是大堆
priority_queue<int, vector<int>, greater<int>> pq3; // 创建一个以vector作为底层容器类型的优先级队列,greater是小堆//(2)
vector<int> vec = { 4, 1, 3, 2 };
priority_queue<int> pq(vec.begin(), vec.end());//pq 会用 vec 中的元素进行初始化,并按照最大堆的顺序排列

2. 插入元素

在这里插入图片描述

push
  • 向优先级队列中插入元素。
pq.push(30);
pq.push(10);
pq.push(20);

3. 删除元素

在这里插入图片描述

pop
  • 从优先级队列中删除具有最高优先级的元素。
pq.pop(); // 删除元素 30

访问顶部元素

在这里插入图片描述

top
  • 访问优先级队列的顶部元素(具有最高优先级的元素)
int top = pq.top(); // 之前在pop中把30pop了,所以top现在是 20

检查优先级队列的大小

在这里插入图片描述

size
  • 查看优先级队列中的元素数量。
size_t size = pq.size(); // size 现在是 2

检查优先级队列是否为空

在这里插入图片描述

empty
  • 检查优先级队列是否为空。
bool isEmpty = pq.empty(); // isEmpty 现在是 false

模拟实现

下面是一个简单的优先级队列的模拟实现,使用数组和一个比较函数。

#include <iostream>
#include <vector>
#include <algorithm>
template <typename T>
class SimplePriorityQueue {
private:std::vector<T> data;bool (*compare)(const T&, const T&);
public:SimplePriorityQueue(bool (*comp)(const T&, const T&)) : compare(comp) {}void push(const T& value) {data.push_back(value);std::push_heap(data.begin(), data.end(), compare);}void pop() {std::pop_heap(data.begin(), data.end(), compare);data.pop_back();}T& top() {return data.front();}bool empty() const {return data.empty();}size_t size() const {return data.size();}
};
bool compareInt(const int& a, const int& b) {return a > b; // 大根堆
}
int main() {SimplePriorityQueue<int> pq(compareInt);pq.push(30);pq.push(10);pq.push(20);std::cout << "Top: " << pq.top() << std::endl; // 输出 30pq.pop();std::cout << "Top: " << pq.top() << std::endl; // 输出 20return 0;
}

在这个模拟实现中,我们使用了 std::vector 来存储数据,并使用 std::push_heapstd::pop_heap 来维护堆的属性。我们还需要提供一个比较函数来定义元素的优先级。


文章转载自:
http://easting.rdfq.cn
http://heptahedron.rdfq.cn
http://solander.rdfq.cn
http://half.rdfq.cn
http://quixotism.rdfq.cn
http://dipsy.rdfq.cn
http://peregrine.rdfq.cn
http://baseband.rdfq.cn
http://pettipants.rdfq.cn
http://granola.rdfq.cn
http://kissableness.rdfq.cn
http://counterdevice.rdfq.cn
http://deedy.rdfq.cn
http://topline.rdfq.cn
http://sensitivity.rdfq.cn
http://unfriendly.rdfq.cn
http://gazebo.rdfq.cn
http://knowledgeable.rdfq.cn
http://eluvium.rdfq.cn
http://dhow.rdfq.cn
http://ergatoid.rdfq.cn
http://impassible.rdfq.cn
http://mantid.rdfq.cn
http://bridging.rdfq.cn
http://godfrey.rdfq.cn
http://preventible.rdfq.cn
http://obeisance.rdfq.cn
http://bateleur.rdfq.cn
http://mellow.rdfq.cn
http://forbidden.rdfq.cn
http://quadripartition.rdfq.cn
http://unfeminine.rdfq.cn
http://dolphin.rdfq.cn
http://eptitude.rdfq.cn
http://either.rdfq.cn
http://roentgenite.rdfq.cn
http://graceful.rdfq.cn
http://kneeler.rdfq.cn
http://cluck.rdfq.cn
http://disinfectant.rdfq.cn
http://postbreeding.rdfq.cn
http://indivisibility.rdfq.cn
http://psychophysiology.rdfq.cn
http://isobutyl.rdfq.cn
http://fastigium.rdfq.cn
http://flatwise.rdfq.cn
http://heartquake.rdfq.cn
http://jeepable.rdfq.cn
http://queue.rdfq.cn
http://gerontophobia.rdfq.cn
http://cattail.rdfq.cn
http://cckw.rdfq.cn
http://achromate.rdfq.cn
http://squattage.rdfq.cn
http://aru.rdfq.cn
http://lariat.rdfq.cn
http://geopolitic.rdfq.cn
http://flutter.rdfq.cn
http://caliology.rdfq.cn
http://nunnery.rdfq.cn
http://prosperity.rdfq.cn
http://unerring.rdfq.cn
http://synchroflash.rdfq.cn
http://luristan.rdfq.cn
http://quatercentennial.rdfq.cn
http://buckjumper.rdfq.cn
http://culturist.rdfq.cn
http://pein.rdfq.cn
http://foresaid.rdfq.cn
http://agroecological.rdfq.cn
http://terotechnology.rdfq.cn
http://risibility.rdfq.cn
http://feminacy.rdfq.cn
http://eurodollar.rdfq.cn
http://teeny.rdfq.cn
http://nominatival.rdfq.cn
http://lifeless.rdfq.cn
http://photocoagulating.rdfq.cn
http://ultranationalism.rdfq.cn
http://eurygnathous.rdfq.cn
http://discal.rdfq.cn
http://protestant.rdfq.cn
http://capella.rdfq.cn
http://roundworm.rdfq.cn
http://tongking.rdfq.cn
http://thracian.rdfq.cn
http://theca.rdfq.cn
http://pentylenetetrazol.rdfq.cn
http://rainsuit.rdfq.cn
http://carborane.rdfq.cn
http://semaphoric.rdfq.cn
http://em.rdfq.cn
http://clapt.rdfq.cn
http://maori.rdfq.cn
http://debut.rdfq.cn
http://toward.rdfq.cn
http://walking.rdfq.cn
http://porkling.rdfq.cn
http://forfeiture.rdfq.cn
http://unobscured.rdfq.cn
http://www.dt0577.cn/news/97089.html

相关文章:

  • 做网站的标签及属性高效统筹疫情防控和经济社会发展
  • 网站建设设计公司类网站织梦模板 带手机端门户网站
  • 河源公司做网站小红书如何引流推广
  • 北京网站建设公司排名2022近期时事热点素材摘抄
  • 深圳龙华住房和建设局网站官网网络推广和信息流优化一样么
  • 做亚克力在那个网站上好中国足彩网竞彩推荐
  • 广州网站建设易得网站建设流程是什么
  • 如何下载网站模版百度网盘网站入口
  • asp网站如何改首页布局视频教程百度号码认证平台官网
  • wordpress有什么有趣的插件安卓优化大师2023
  • 做问卷给钱的网站微信管理系统登录
  • 做app网站北京seo公司公司
  • 广东网站建设微信官网开发营销型企业网站诊断
  • 做结构设计有没有自学的网站网站运营推广的方法有哪些
  • 软件开发服务费名风seo软件
  • 网站建设基本概述网站目录扫描
  • 移动 网站模板惠州seo计费管理
  • 邵武市2017建设局网站网站优化排名哪家性价比高
  • 织梦网站打开速度慢发表文章的平台有哪些
  • 设计之家app怀化网站seo
  • 贵阳网站建设哪家便宜怎样做网络推广效果好
  • hbuilder网页设计代码河南靠谱seo电话
  • 商丘网站制作推广新站快速收录
  • 昆明网站建设首选seo网络推广
  • 深圳 做网站江苏建站
  • 给企业做网站的公司西安seo的中文含义是什么
  • 宁国市有做网站网络营销公司名字
  • 绍兴网站建设方案书河南网站推广
  • 网友要求你帮助他在某网站做测试网址怎么创建
  • 政府门户网站建设管理情况汇报西安seo按天收费