Home » C++ algorithm move_backward() function

C++ algorithm move_backward() function

by Online Tutorials Library

C++ Algorithm Functions move backward ()

The function is used for moving of elements in the backward order, it accepts three arguments and then moves the elements belonging to the range [first,last). The moving of elements begins in the reverse order with termination point at ‘result’.

Syntax

Parameter

first: It is a bidirectional iterator to the first element of the range, where the element itself is included in the range.

last: It is a bidirectional iterator to the last element of the range, where the element itself is not included in the range.

result: It is a bidirectional iterator to the final position of moved elements.

Return value

The function returns an iterator the first element to the sequence of moved ones.

Example 1

Output:

elem contains: [keto] [kunal] [suraj] [shweta] [chhavi] [] [] [] [] []  

Example 2

Output:

u1 contains : 5 9 14 8 18  u2 contains : 5 5 5 5    u1 after applying move_backward function contains: 5 5 5 8 18  

Complexity

The complexity of the function is linear starting from the first element to the last one.

Data races

Some or all of the container objects are accessed.

Exceptions

The function throws an exception if any of the container elements throws one.

You may also like