`
insertyou
  • 浏览: 919417 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

STL算法概述

 
阅读更多

#include<algorithm> //C++标准库算法

#include<functional>//仿函数和函数配接器

1.nonmodifying algorithm 非变动性算法(不改动元素,即只能读取)

2.modifying algorithm 变动性算法

3.removing algorithm 移除性算法

4.mutating algorithm 变序性算法

5.sorting algorithm 排序算法

6,sorted range algorithm已序区间算法

7.numeric algorithm 数值算法

difference_type用于测定距离,区别正负

1.非变动性算法

(1) for_each(begin,end,Unary_func op) 具体见另外博客

(2) difference_type count (begin,end,const T&value); //返回value的个数

(3) difference_type count_if (begin,end,Unarypredicate op); //返回op为true的元素个数

(4) iterator min_element(begin,end); //默认less than

iterator min_element(begin,end,compFunc op); //op(elem1,elem2);

(5) iterator max_element(begin,end);

iterator max_element(begin,end,compFunc op);

(6) iterator find(begin,end,const T&value);

(7) iterator find_if(begin,end,UnaryPredicate op);

如果是已序区间用lower_bound(),upper_bound(),equal_range(),binary_search()可获更高性能

(8) Input_iterator search_n(begin,end,Size count,const T& value); //连续count个元素值全是value

Input_iterator search_n(begin,end,Size count,const T&value,BinaryPredicate op);

//连续count个元素造成op为true, op(elem,value)

(9) FowardIterator search(begin1,end1,begin2,end2); //在[begin1,end1)中寻找与[begin2,end2)相同的元素

FowardIterator search(begin1,end1,Searchbegin2,Searchend2,BinaryPredicate op);

//op(elem,searchElem),

(10) Forward_Iterator find_end(begin1,end1,searchBegin2,searchEnd2);

//[begin1,end1)中最后出现的[searchBegin2,searchEnd2)

Forward_Iterator find_end(begin1,end1,searchBegin2,searchEnd2,BinaryPredicate op);

//op(elem,searchElem);

(11)Find_first_of 查找与顺序无关。

Forward_Iterator find_first_of(begin1,end1,searchBegin2,searchEnd2)

//返回一个既在区间[begin1,end1)出现也在[searchBegin2,searchEnd2)出现的元素位置

Forward_Iterator find_first_of(begin1,end1,searchBegin2,searchEnd2,BinaryPredicate op);

//返回一个区间[begin1,end1)和区间[searchBegin2,searchEnd2)内进行op(elem,searchElem)为true

(12) InputIterator adjacant_find(begin,end); //返回连续两个相等元素的第一个位置

InputIterator adjacant_find(begin,end,BinaryPredicate op);

//op(elem,nextElem),连续两个元素使以下二元判断式的结果为true

(13) bool equal(begin1,end1,begin2);

bool equal(begin1,end1,begin2,BinaryPredicate op); //op(elem,cmpElem);

(14) pair<InputIterator1,InputIterator2> mismatch(InputIterator1 begin,InputIterator1 end,InputIterator2 cmpBeg)

返回[begin,end)和cmpBeg开头的区间第一组相异的对应元素

pair<InputIterator1,InputIterator2> mismatch(InputIterator1 begin,InputIterator1 end,InputIterator2 cmpBeg,

BinaryPredicate op);

op(elem,cmpElem); 返回使判断式为false的对应元素

(15) bool lexicographical_compare(begin1,end1,begin2,end2);

bool lexicographical_compare(begin1,end1,begin2,end2,ComFunc op);

op(elem1,elem2); elem1小于elem2则为true

字典顺序定义:

1.数量不同,如果第一个序列数量少,则为true

2.相等则false

分享到:
评论

相关推荐

    stl算法的知识

    ### STL算法概述 在C++标准模板库(Standard Template Library,简称STL)中,算法是一组用于操作容器内元素的通用函数。STL算法的设计目的是为了提高代码的复用性和可读性,并且能够有效地处理各种数据结构。本文...

    stl的介绍 STL算法作为模板函数提供

    STL算法是一系列通用的操作,可以应用于任何类型的容器或数组。常见的算法包括但不限于: - **排序算法**:如`sort()`,用于对容器进行排序。 - **查找算法**:如`find()`,用于在容器中查找特定元素。 - **修改...

    STL和常用算法简介

    #### 一、STL概述 STL(Standard Template Library,标准模板库)是C++标准库的重要组成部分,它提供了一系列通用的数据结构和算法,极大地简化了程序开发工作,提高了代码的复用性。STL主要由四个部分组成:容器、...

    c++语言STL - 算法部分讲解(大连理工资深教授)

    #### C++ STL简介及算法概述 C++标准模板库(Standard Template Library,简称STL)是一组C++编程工具的集合,它提供了许多高效且可复用的数据结构和算法。STL主要包括五个核心组件:容器、迭代器、算法、函数对象...

    STL SET 集合算法

    本文将详细介绍`set`容器的基本用法以及与之相关的几种STL算法,包括但不限于`set_difference`、`set_union`、`set_intersection`、`set_symmetric_difference`等。 #### 示例代码解析 ```cpp #include #include #...

    STL排序概述

    这篇概述主要讲解了如何使用STL中的`sort`函数,以及如何根据具体需求选择合适的排序算法。 1.1 所有`sort`算法介绍 STL提供的排序算法主要包括`sort`、`stable_sort`、`partial_sort`和`partial_sort_copy`。这些...

    acm ————stl

    STL算法部分包含了许多常用的模板函数,例如: - **for_each**:对容器中的每个元素应用某个函数。 - **sort**:对容器中的元素进行排序。 - **reverse**:反转容器中元素的顺序。 - **find**:查找容器中是否存在...

    ACM STL的应用

    1. STL概述:STL是C++标准库的一部分,它将数据结构和算法进行了高度的抽象和封装。STL主要包括容器(Container)、算法(Algorithm)和迭代器(Iterator)三大类组件。容器负责数据的存储,算法负责数据的处理,...

    C++模板与STL.pptx

    模板 函数模板 类模板 断言 STL概述 STL容器 STL 迭代器 STL 算法 STL其他构件

    标准模板库STL参考手册

    **STL算法** STL包含大量预定义的算法,可以应用于任何容器或迭代器范围内的元素。常见的算法有: 1. **排序算法**:`sort()`对容器进行排序,`stable_sort()`保持相等元素的相对顺序。 2. **查找算法**:`find()`、...

    STL源码剖析.pdf

    4. **算法优化**:分析STL算法的实现逻辑,比如排序算法(如quick_sort、merge_sort)、查找算法(如binary_search)等,理解其时间复杂度和空间复杂度,以及如何根据具体需求选择合适的算法。 5. **函数对象与...

    C++ STL 开发技术导引(随书源码)

    本书共分5篇26章,以“C++编程技术→C++ STL泛化技术基础→C++ STL容器技术→C++ STL算法技术→C++ STL迭代器技术”为线索具体展开,通过大量的源码分析和应用实例,详细介绍了C++ STL的技术原理和使用方法。...

    stl相关资料 effective stl

    4. **基本算法示例**:展示几个常用的STL算法,如排序、查找等。 5. **STL在实际编程中的应用**:通过实例展示STL在实际问题中的解决策略。 通过这三个文档的学习,你可以全面地了解STL,从基本概念到高级用法,...

    STL 源码剖析pdf 高清版(非扫描)

    1. **STL概述**:首先,书中会介绍STL的基本概念,包括其设计理念和结构,如泛型编程、容器、迭代器和算法的相互配合。 2. **容器**:STL提供了多种数据结构,如vector(动态数组)、deque(双端队列)、list(双向...

    C++ STL l速成 适合acm

    STL概述 STL是一个通用的数据结构和算法库,具有数据结构和算法的分离特点。这种分离使得STL变得非常通用,可以用来操作几乎任何数据集合,包括链表、容器和数组。 STL的算法作为模板函数提供,具有广泛的通用性...

    30分钟掌握stl

    #### STL算法的特点 STL中的算法以模板函数的形式提供,这意味着它们可以被用于多种不同类型的数据结构。在STL中,所有算法都是通过模板定义的,这样就可以适用于任何支持所需操作的数据类型。例如: - `sort()`:...

    STL源码剖析-简体中文PDF

    ### STL源码剖析 ...它不仅提供了丰富的代码示例,更深入浅出地揭示了STL中各种数据结构和算法的设计思想与实现细节。通过阅读本书,读者可以更加深刻地理解C++语言的魅力所在,并为后续开发工作打下坚实的基础。

Global site tag (gtag.js) - Google Analytics