Computer Science Homework Solutions
Problem
#133926

Data Structures with C++ Using STL

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


Please provide a complete program if it makes sense.

Attached file(s):
Attachments
8.20.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

8.20.doc
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

Please provide a complete program if it makes sense.

Solution Summary

Put elements in a queue, the change the order of them.

Solution
What is this?
By OTA - Overall OTA Rating
Yanfang Li, PhD - 4.9/5
Purchase Cost Now
$2.19 CAD (was ~$11.97)
Included in Download
  • Plain text response
  • Attached file(s):
    • n2front.txt
    • queue1.zip
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Queues C++ - Write a function template, reverseStack, that takes a parameter a stack object and a queue object whose elements are of the same type. The function reverseStack uses the queue to reverse the elements ...
  • Queues C++ - Write the definition of the function template moveNthFront that takes as a parameter a queue and a positive integer, n. The function moves the nth element of the queue to the front. The order of the ...
  • Data Structures with C++ Using STL - List the elements in the queue after each of the following operations: queue intQueue; intQueue.push(18); intQueue.push(2); intQueue.push(intQueue.front()); intQueue.push(intQueue.front( ...
  • Data Structures with C++ Using STL - Write a function template void stackClear (stack& s); that clears a stack s. Why is it critical that s be passed by reference? Please provide a complete program if it makes s ...
  • Data Structures with C++ Using STL - Declare a stack, queue, and priority queue of integers, as follows: stack s; queue q; priority_queue pq; Assume that you input the integer sequence 5 8 12 15 1 3 18 25 18 35 ...
Browse