c – copy_backward和reverse_copy之间的区别?

我正在阅读C primer并看到这两个似乎具有相同功能函数.谁能帮忙告诉我两者有什么区别?谢谢.

解决方法

reverse_copy实际上以相反的顺序放置元素.
1 2 3 4 5 - > 5 4 3 2 1

copy_backward只是向后复制元素,但保留它们的相对顺序.

1 2 3 4 5

首先复制5,但放在最后一个位置.所以你的输出仍然是:

1 2 3 4 5

http://en.cppreference.com/w/cpp/algorithm/copy_backward

copies the elements from the range,defined by [first,last),to another range ending at d_last. The elements are copied in reverse order (the last element is copied first),but their relative order is preserved.

http://en.cppreference.com/w/cpp/algorithm/reverse_copy

copies the elements from the range [first,last) to another range beginning at d_first in such a way that the elements in the new range are in reverse order.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...