C++ std::greater用法及代码示例

std::greater是用于执行比较的功能对象。它被定义为greater-than不等式比较的Function对象类。这可用于更改给定功能的功能。这也可以与各种标准算法一起使用,例如排序,优先级队列等。

头文件:

#include <functional.h>

模板类别:

template <class T> struct greater;

参数: T是要通过函数调用进行比较的参数类型。

返回值:它返回布尔变量,如下所示:


 

  • 真正:如果两个元素说(a&b)使得a> b。
  • 假:如果a <b。

用法:

对于顺序容器数组、vector等:

sort(arr.begin(), arr.end(), greater<int>()); 

对于关联式容器,如优先队列、堆,使用

priority_queue<int>  //默认降序队列,大顶堆
priority_queue<int,vector<int>,less<int>> //降序队列,大顶堆
priority_queue<int,vector<int>,greater<int>>  //升序队列,小顶堆

  • 14
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Bjarne Stroustrup, "Programming: Principles and Practice Using C++"Addison-Wesley Professional | 2008 | ISBN: 0321543726 | 1272 pages | PDF | 129 MBAn Introduction to Programming by the Inventor of C++Preparation for Programming in the Real WorldThe book assumes that you aim eventually to write non-trivial programs, whether for work in software development or in some other technical field.Focus on Fundamental Concepts and TechniquesThe book explains fundamental concepts and techniques in greater depth than traditional introductions. This approach will give you a solid foundation for writing useful, correct, maintainable, and efficient code.Programming with Today’s C++The book is an introduction to programming in general, including object-oriented programming and generic programming. It is also a solid introduction to the C++ programming language, one of the most widely used languages for real-world software. The book presents modern C++ programming techniques from the start, introducing the C++ standard library to simplify programming tasks.For Beginners–And Anyone Who Wants to Learn Something NewThe book is primarily designed for people who have never programmed before, and it has been tested with more than 1,000 first-year university students. However, practitioners and advanced students will gain new insight and guidance by seeing how a recognized master approaches the elements of his art.Provides a Broad ViewThe first half of the book covers a wide range of essential concepts, design and programming techniques, language features, and libraries. Those will enable you to write programs involving input, output, computation, and simple graphics. The second half explores more specialized topics, such as text processing and testing, and provides abundant reference material. Source code and support supplements are available from the author’s website.Part 1depositfiles.comuploading.commirrorPart 2depositfiles.comuploading.commirrorNot all books on AvaxHome appear on the

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值