c – copy_backward和reverse_copy之间的区别?

前端之家收集整理的这篇文章主要介绍了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&C++相关文章