C++算法for_each()和 includes()

 

算法

返回值

作用

for_each()

_Fn1

对范围内的每一个元素进行某个动作

includes()

bool

涵盖于

for_each()的参数

_InIt _First, _InIt _Last, _Fn1 _Func

includes()的参数

_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2

 

vector<int> createStaticArr()

{

    vector<int> vectorInt;

    vectorInt.push_back(1);

    vectorInt.push_back(2);

    vectorInt.push_back(3);

    vectorInt.push_back(4);

    vectorInt.push_back(5);

    vectorInt.push_back(6);

    vectorInt.push_back(7);

    vectorInt.push_back(8);

    showArr(vectorInt);

    return vectorInt;

}

 

void showArr(vector<int> Arr)

{

    vector<int>::iterator iteArr = Arr.begin();

    for (iteArr ; iteArr != Arr.end(); iteArr++)

    {

        cout << *iteArr << "\t";

    }

    cout << endl;

}

 

//仿函数

void my_for_each_Fun(int &n)

{

    if (n > 5)

    {

        n += 5;

    }

}

 

void main()

{

    cout << "第一条:"; vector<int> arr1 = createStaticArr();

    cout << endl;

    for_each(arr1.begin(), arr1.end(),my_for_each_Fun);

    cout << "进行了for_each()方法后:"; showArr(arr1);

 

    cout << "第二条:"; vector<int> arr2 = createStaticArr();

    cout << endl;

    bool temp =

    includes(arr1.begin(), arr1.end(), arr2.begin(), arr2.begin() + 3);

    if (temp)

    {

        cout << "arr1包含arr2" << endl;

    }

}

 

//在includes()中,arr1包含arr2所有元素时返回true。

 

 

运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
第一篇 预备知识 第1章 C++编程技术 2 1.1 类和对象 2 1.2 类的继承 5 1.3 函数重载 5 1.4 访问控制 7 1.5 操作符重载 8 1.6 显式类型转换 9 1.7 异常处理 13 1.8 名字空间 17 1.9 友员函数 20 1.10 内联函数 21 1.11 静态成员 22 1.12 本章小结 23 第2章 C++模板技术 25 2.1 函数模板 25 2.2 类模板 27 2.3 模板完全特化 28 2.4 函数模板重载 30 2.5 类模板继承 30 2.6 本章小结 31 第3章 C++ I/O流技术 32 3.1 I/O流类 32 3.2 标准输入输出 34 3.3 文件输入输出 36 3.4 流的格式控制 41 3.5 本章小结 45 第二篇 C++ STL泛化技术基础 第4章 C++ STL泛型库概述 48 4.1 C++ STL的发展历程 48 4.2 C++ STL的各种实现版本 49 4.2.1 HP STL 49 4.2.2 SGI STL 50 4.2.3 STLport 50 4.2.4 P.J.Plauger STL 50 4.2.5 Rouge Wave STL 50 4.3 C++ STL的Visual C++编译 50 4.4 C++ STL的体系结构 52 4.4.1 容器(Container) 52 4.4.2 迭代器(Iterator) 53 4.4.3 算法(Algorithm) 53 4.4.4 函数对象(Function Object) 54 4.4.5 适配器(Adapter) 55 4.4.6 内存分配器(Allocator) 56 4.4.7 概念(Concept)和模型(Model) 56 4.5 C++ STL存在的一些问题 57 4.6 本章小结 57 第5章 C++ STL泛化技术分析 58 5.1 算法和迭代器 58 5.1.1 算法 58 5.1.2 迭代器 61 5.1.3 函数对象 65 5.1.4 适配器 68 5.2 内存分配器和容器 74 5.2.1 内存分配器 75 5.2.2 容器 77 5.3 概念 82 5.3.1 基础性概念 82 5.3.2 容器概念 84 5.3.3 迭代器概念 86 5.3.4 函数对象概念 88 5.4 本章小结 89 第三篇 C++ STL容器技术 第6章 vector向量容器 92 6.1 vector技术原理 92 6.2 vector应用基础 94 6.3 本章小结 101 第7章 deque双端队列容器 102 7.1 deque技术原理 102 7.2 deque应用基础 108 7.3 本章小结 115 第8章 list双向链表容器 116 8.1 list技术原理 116 8.2 list应用基础 124 8.3 本章小结 131 第9章 slist单向链表容器 132 9.1 slist技术原理 132 9.2 slist应用基础 140 9.3 本章小结 148 第10章 bit_vector位向量容器 149 10.1 bit_vector技术原理 149 10.2 bit_vector应用基础 156 10.3 本章小结 161 第11章 set集合容器 162 11.1 set技术原理 162 11.2 set应用基础 181 11.3 本章小结 186 第12章 multiset多重集合容器 187 12.1 multiset技术原理 187 12.2 multiset应用基础 190 12.3 本章小结 196 第13章 map映照容器 197 13.1 map技术原理 197 13.2 map应用基础 200 13.3 本章小结 206 第14章 multimap多重映照容器 207 14.1 multimap技术原理 207 14.2 multimap应用基础 210 14.3 本章小结 216 第15章 hash_set哈希集合容器 217 15.1 hash_set技术原理 217 15.2 hash_set应用基础 230 15.3 本章小结 234 第16章 hash_map哈希映照容器 235 16.1 hash_map技术原理 235 16.2 hash_map应用基础 237 16.3 本章小结 242 第17章 string基本字符序列容器 243 17.1 string技术原理 243 17.2 string应用基础 258 17.3 本章小结 264 第18章 stack堆栈容器 265 18.1 stack技术原理 265 18.2 stack应用基础 266 18.3 本章小结 269 第19章 queue队列容器 270 19.1 queue技术原理 270 19.2 queue应用基础 271 19.3 本章小结 274 第20章 priority_queue优先队列容器 275 20.1 priority_queue技术原理 275 20.2 priority_queue应用基础 278 20.3 本章小结 281 第四篇 C++ STL算法技术 第21章 非变易算法 284 21.1 逐个容器元素for_each 284 21.2 查找容器元素find 285 21.3 条件查找容器元素find_if 286 21.4 邻近查找容器元素adjacent_find 287 21.5 范围查找容器元素find_first_of 289 21.6 统计等于某值的容器元素个数count 290 21.7 条件统计容器元素个数count_if 291 21.8 元素不匹配查找mismatch 293 21.9 元素相等判断equal 295 21.10 子序列搜索search 296 21.11 重复元素子序列搜索search_n 299 21.12 最后一个子序列搜索find_end 301 21.13 本章小结 303 第22章 变易算法 304 22.1 元素复制copy 304 22.2 反向复制copy_backward 305 22.3 元素交换swap 306 22.4 迭代器交换iter_swap 307 22.5 区间元素交换swap_ranges 308 22.6 元素变换transform 309 22.7 替换 310 22.8 条件替换replace_if 311 22.9 替换和复制replace_copy 312 22.10 条件替换和复制replace_copy_if 313 22.11 填充fill 314 22.12 n次填充fill_n 315 22.13 随机生成元素generate 316 22.14 随机生成n个元素generate_n 317 22.15 移除复制remove_copy 318 22.16 条件移除复制remove_copy_if 319 22.17 移除remove 320 22.18 条件移除remove_if 321 22.19 不连续重复元素复制unique_copy 322 22.20 剔除连续重复元素unique 324 22.21 元素反向reverse 325 22.22 反向复制reverse_copy 326 22.23 旋转rotate 327 22.24 旋转复制rotate_copy 329 22.25 随机抖动random_shuffle 330 22.26 随机采样random_sample 331 22.27 容器分割partition 333 22.28 容器稳定分割stable_partition 335 22.29 本章小结 338 第23章 排序算法 339 23.1 元素入堆push_heap 339 23.2 创建堆make_heap 343 23.3 元素出堆pop_heap 348 23.4 堆排序sort_heap 351 23.5 是否为堆is_heap 352 23.6 局部排序partial_sort 354 23.7 局部排序复制partial_sort_copy 356 23.8 排序sort 359 23.9 归并merge 366 23.10 内部归并inplace_merge 368 23.11 稳定排序stable_sort 376 23.12 是否排序is_sorted 383 23.13 第n个元素nth_element 384 23.14 下确界lower_bound 386 23.15 上确界upper_bound 388 23.16 等价区间equal_range 390 23.17 折半搜索binary_search 392 23.18 子集合includes 393 23.19 集合求并set_union 394 23.20 集合求交set_ intersection 396 23.21 集合求差set_difference 398 23.22 集合求异set_symmetric_difference 399 23.23 最小值min 401 23.24 最大值max 402 23.25 最小元素min_element 403 23.26 最大元素max_element 404 23.27 字典比较lexicographical_compare 405 23.28 下一排列组合next_permutation 406 23.29 上一排列组合prev_permutation 409 23.30 本章小结 411 第24章 数值算法 412 24.1 递增赋值iota 412 24.2 元素求和accumulate 413 24.3 两序列元素内积inner_product 414 24.4 部分元素求和partial_sum 415 24.5 相邻元素求差adjacent_difference 417 24.6 n次方计算power 419 24.7 本章小结 421 第五篇 C++ STL迭代器技术 第25章 输入输出流迭代器 424 25.1 输入流迭代器 424 25.2 输出流迭代器 426 25.3 本章小结 427 第26章 插入/反向/存储迭代器 428 26.1 向前插入迭代器 428 26.2 向后插入迭代器 429 26.3 插入迭代器 431 26.4 反向迭代器 432 26.5 反向双向迭代器 434 26.6 原始存储迭代器 435 26.7 本章小结 437 附录 STL版权说明 438
Arbitrary Length FFT ------------------------------------------------------------------------ NOTE : This is copyrighted material, NOT public domain. See below. ------------------------------------------------------------------------ Contents: This packet contains the C source for a mixed-radix FFT routine. It performs a fast discrete Fourier transform (FFT) of a complex sequence, x, of an arbitrary length, n. The output, y, is also a complex sequence of length n. y[k] = sum(x[m]*exp(-i*2*pi*k*m/n), m=0..(n-1)), k=0,...,(n-1) The largest prime factor of n must be less than or equal to the constant, maxPrimeFactor defined in mixfft.c. The input/output variables are each stored in two arrays comprising the real part and the imaginary part respectively. The routine is accompanied by a demo program, fftbench.c, that demonstrates the numerical capabilities. It measures the execution time as well. If you wish to test the capabilities of another FFT routine, the fftbench.c is easy to modify. ------------------------------------------------------------------------ Filelist: mixfft.c 21.120 001030 The C source for the mixed-radix FFT. fftbench.c 8.724 001030 The C source for FFT benchmark program. fftbench.exe 62.976 001030 The PC executable. readme.txt This file. ------------------------------------------------------------------------ Platforms: PC: The included fftbench.exe was generated using the Microsoft Visual C++ compiler with the following compile options: /nologo /Gs /G2 /W4 /AH /Ox /D "NDEBUG" /D "_DOS" /FR It was tested on a 50MHz 486DX. Please refer to fftbench.c for some benchmarks. (jjn, March 1996) Other: Your experience with other platforms are warmly welcomed. Please e-mail me. ------------------------------------------------------------------------ Conditions: The source code in this packet is copyrighted material. Non-commercial use of the source code is free. A $100 fee must be paid if used commercially. Please contact me at jjn@get2net.dk and register your copy. The $100 fee includes up to one hour of assistance related to your use of the code. A trial period of 14 days is allowed. If the code is used for professional (paid) research and development for non-profit organisations like universities a reduced fee of $20 must be paid. The commercial license allows you to include the compiled code in a product or to use the code on a regular basis. You are however NOT allowed to sell the source code. Distribution of the complete unaltered package, including this file, is free. This includes commercial CD's. ------------------------------------------------------------------------ Author: Jens Joergen Nielsen For non-commercial use only. Bakkehusene 54 A $100 fee must be paid if used 2970 Hoersholm commercially. Please contact. DENMARK mailto:jjn@get2net.dk All rights reserved. October 2000. Check my homepage for updates and FAQ's http://home.get2net.dk/jjn ------------------------------------------------------------------------ Release notes: V.0.1 950301 Initial MIXFFT release. V.0.3 960317 Input/output variables have separate arrays for real and imag part. The speed of prime factors larger than 7 is more than doubled. V.0.4 980103 e-mail address changed. V.0.5 001030 Memory allocation in FFTBench changed, now calloc is used. Error reporting when primefactor is larger than maxPrimeFactor has been corrected. ------------------------------------------------------------------------

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值