How to move elements in a queue


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

8

5

17

3

7

front                                                                                 back

After

3

8

5

17

7

front                                                                                 back

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: How to move elements in a queue
Reference No:- TGS01937573

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)