Sum a Queue Without Emptying It
mediumQuestion 489Write a function int sumQueue(queue<int> q) that returns the sum of every element in the queue. Return 0 for an empty queue.
Each test prints the returned sum on one line, then the size of the caller's queue on the next line. For a queue holding 4, 5, 6 the output is exactly what is shown in Expected Output.
For an empty queue the output is: 0 0
Do NOT write a main function.
Expected output
15 3 0 0
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.