Decide what to return on 'deque' operation (Queue)

Imagine I was given this task:
char CharQueue2::dequeue(){//Write code here to make this work }


Then I write the below pop_back() operation.
Question is, if I need to return a 'char' type as per the requirement, what would be the return value here to help me validate the operation is successful?
1
2
3
4
5
6
7
char CharQueue2::dequeue()
{
    vardeque.pop_back();
    return {}; //*** What should I return here to demonstrate dequeue is successful?
   // I could return vardeque.size() for example, but that is not a data type 'char'... interesting.

}
Last edited on
Did you try to look at the documentation for std::queue?

Since a std::queue doesn't have a pop_back() you'll need to decide what you want to happen based on the methods available from the standard container.

Hey, thanks for the question regarding the documentation. In reality I did check and I see that A deque is a double-ended queue.

I did check and I see the option 'pop_back()' and it appears to accomplish the goal to remove element from the queue.

I guess if I just return {} it is functional. I just wanted to see if you have a better approach for this. Thanks.
Okay I misread your problem, I saw "queue".

Anyway prior to the pop_back() you could get the value of "back" and return that after the pop_back() if you so desire.

EDIT: What is the purpose of this exercise? You keep mentioning "Queue" in your thread titles, so are you trying to emulate a queue or a deque?

If it's a for a queue then a queue shouldn't have a pop_back() function since queue will pop the "front".

If it's for a deque then you probably should be making your own container not using the std::deque.

Last edited on
It is a deque operation for sure.
Then should you be using std::deque or should you be using something else?

Topic archived. No new replies allowed.