zoukankan      html  css  js  c++  java
  • [啃书] 预告篇

    max()/min()/abs()函数

    swap()函数

    reverse()函数

    next_permutation()函数

    fill()函数

    sort()函数

    头文件需要

    #include<algorithm>
    using namespace std

    使用方法

    sort(首元素地址(必填), 尾元素地址的下一个地址(必填), 比较函数(非必填))

    不写比较函数则默认递增排序。

    示例

    对int数组

    输出结果:

    2 4 5 9 6 -1

    -1 2 4 5 6 9

    对double数组

    输出结果:-2.1 1.4 9

    对char数组

    输出结果:AKTW

    需要比较函数的情况

    int/double/char的递减排序

    输出结果:4 3 2 1

    对于double/char也类似

    结构体数组排序

    输出结果:

    3 1

    2 2

    1 3

    若增加判断条件:x相等,则y大的排在后面(cmp函数代码如下)

    容器的排序

    STL标准容器中只有vector/string/deque可以使用sort排序(set/map等容器是用红黑树实现的,本身就有序所以不允许使用)

    vector排序

    输出结果:3 2 1

    string排序

    按字典顺序

    输出结果:

    aaa

    bbbb

    cc
    按string长短顺序

    输出结果:

    cc

    aaa

    bbbb

    lower_bound()/upper_bound()函数

  • 相关阅读:
    strcpy 详解
    c/c++中static详解
    c/c++中const详解
    12、Java中的接口
    11、java中的模板方法设计模式
    10、java中的抽象类
    9、java中的final关键字
    8、java继承中的this和super的应用
    7、java实现的两种单例模式
    6、java中的构造代码块
  • 原文地址:https://www.cnblogs.com/cc1997/p/13178303.html
Copyright © 2011-2022 走看看