Purchase Solution

Move elements in C++ queue using template

Not what you're looking for?

Ask Custom Question

See attached file.

Write a function

template<typename T>
void n2front (queue<T>& 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

Please provide a complete program if it makes sense.

Attachments
Purchase this Solution

Solution Summary

The solution puts the elements in a queue, then changes the order of them (see attachment).

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.