金海佳学C++primer 练习9.4/9.5
来源:互联网 发布:增加usb电流软件 编辑:程序博客网 时间:2024/06/05 23:53
给定区间查找值
Practice9.4
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <list>#include <iterator>#include <cmath>#include <cstring>#include <forward_list>using namespace std;void print(vector<int> ivec) { for(auto i : ivec) { cout << i << " "; } cout << endl;}bool find_value(vector<int>::iterator b, vector<int>::iterator e, int value){ // "it != e" !!! // [ ) for(auto it = b; it != e; it++) { if(*it == value) { return true; } } return false;}int main() { vector<int> ivec = {0, 1, 3, 4, 5, 6, 7, 8}; auto b = ivec.begin(); auto e = ivec.begin(); e++, e++, e++, e++; cout << "b -----> " << *b << endl; cout << "e -----> " << *e << endl; /* test1 */ cout << find_value(b,e,3) << endl; /* test2 */ cout << find_value(b,e,12) << endl; return 0;}
Output
b -----> 0e -----> 510
Practice9.5
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <list>#include <iterator>#include <cmath>#include <cstring>#include <forward_list>using namespace std;void print(vector<int> ivec) { for(auto i : ivec) { cout << i << " "; } cout << endl;}vector<int>::iterator find_value_2(vector<int>::iterator b, vector<int>::iterator e, int value){ // "it != e" !!! // [ ) for(auto it = b; it != e; it++) { if(*it == value) { return it; } } cout << "Find nothing" << endl; return b;}int main() { vector<int> ivec = {0, 1, 3, 4, 5, 6, 7, 8}; auto b = ivec.begin(); auto e = ivec.begin(); e++, e++, e++, e++; cout << "b -----> " << *b << endl; cout << "e -----> " << *e << endl; /* test1 */ cout << *(find_value_2(b,e,3)) << endl; /* test2 */ cout << *(find_value_2(b,e,12)) << endl; return 0;}
Oupout
b -----> 0e -----> 53Find nothing0
Keep on going never give up
阅读全文
0 0
- 金海佳学C++primer 练习9.4/9.5
- 金海佳学C++primer 练习9.14
- 金海佳学C++primer 练习9.20
- 金海佳学C++primer 练习9.27
- 金海佳学C++primer 练习9.28
- 金海佳学C++primer 练习9.31
- 金海佳学C++primer 练习9.41
- 金海佳学C++primer 练习9.43
- 金海佳学C++primer 练习9.44
- 金海佳学C++primer 练习9.47
- 金海佳学C++primer 练习9.15/9.16
- 金海佳学C++primer 练习9.18/9.19
- C++Primer第五版 9.4节练习
- C++Primer 练习 12.7
- c++primer练习10.9
- c++primer练习10.11
- c++primer练习10.13
- c++primer练习10.14
- Django数据库操作中的多对多关系
- 目标检测RCNN-YOLO-SSD系列学习资料汇总
- Markdown字体颜色、大小
- PLSQL编程4:plsql游标的用法
- HttpClient容易忽视的细节——连接关闭
- 金海佳学C++primer 练习9.4/9.5
- iOS 验证码倒计时
- 机器学习
- [POJ](3050)Hopscotch---- 裸dfs+set容器
- Python写Gui窗口
- [POJ1741]Tree(点分治+讲解)
- 【Scikit-Learn 中文文档】双聚类
- Uva 10763
- 阿里云工业互联网云平台落地广东,智造大省打响「互联网+先进制造」登陆战