C++primer 10.4.3节练习

练习10.34

 1 #include <string>
 2 #include <vector>
 3 #include <algorithm>
 4 #include <list>
 5 #include <functional>
 6 #include <iterator>
 7 #include <fstream>
 8 using namespace std;
 9 using namespace placeholders;
10 
11 int main()
12 {
13     vector<int> vec{ 1,2,3,4,5,6,7,8,9 };
14     for (auto it = vec.crbegin(); it != vec.crend(); ++it)
15         cout << *it << endl;
16     system("pause");
17     return 0;
18 }

练习10.35

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 int main()
15 {
16     vector<int> vec{ 1,2,3,4,5,6,7,8,9 };
17     list<int> vec1;
18     copy(vec.begin(), vec.end(), front_inserter(vec1));
19     for (auto c : vec1)
20         cout << c << endl;
21     system("pause");
22     return 0;
23 }

 

练习10.36

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 int main()
15 {
16     vector<int> vec{ 1,2,3,4,5,6,7,8,9 };
17     list<int> vec1{ 0,1,2,3,4,5,6,7,8,9,0,10,0,3,0,5 };
18     auto wc = find(vec1.crbegin(), vec1.crend(), 0);
19     cout << *wc << endl;
20     system("pause");
21     return 0;
22 }

 

练习10.37

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 int main()                //之所以采取这样的方法,是因为这样即使容器中有重复的元素也能很好的进行逆序输出 
15 {
16     vector<int> vec1{ 20,1,3,7,4,10,24,3,0,5 };
17     list<int> li;
18     sort(vec1.begin(), vec1.end());
19     for (auto c : vec1)
20         cout << c << " ";
21     cout << endl;
22     auto w1 = find(vec1.begin(), vec1.end(), 3);
23     auto w2 = find(vec1.rbegin(), vec1.rend(), 7);
24     copy(w1, w2.base(), front_inserter(li));
25     for (auto c : li)
26         cout << c << " ";
27     cout << endl;
28     system("pause");
29     return 0;
30 }

 

转载于:https://www.cnblogs.com/wuyinfenghappy/p/7365287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值