Discuss the below:
Q: Write a function
template
void n2front (queue& q, int n);
that moves the nth element (counting from the front, which is element 1) of the queue to the front, leaving the order of all other elements unchanged. The function throws the rangeError exception if n < 1 or n> q.size(). The figure illustrates the action of n2front() for an integer queue and n = 4.
n = 4 (4th element of queue)
Before
front back
After
front back