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++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...