网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

c++ STL容器reverse如何使用

时间:2024-11-04 09:13:44

1、头文件:如果想要使用reverse的话,必须要使用头文件#include <algorithm>

c++ STL容器reverse如何使用

2、该容器内部的殂翼瑟擀实现:调用了iter_swap实现了元素的互换:template<classBidirectionalIterator>void re即枢潋雳verse (BidirectionalIterator first, BidirectionalIterator last){ while((first!=last)&&(first!=--last)) { std::iter_swap (first,last); ++first; }}

c++ STL容器reverse如何使用

4、参数:BidirectionalIterator first与BidirectionalIterator last分别是一个序列的起点和中点。类型是内嵌的Iterator型。

c++ STL容器reverse如何使用

6、输出结果:myvector contains: 9 8 7 6 5 4 3 2 1

c++ STL容器reverse如何使用
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com