• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ question

Ordy

Member
In C++, if you have a queue where maxQue is 5 , the queue,front is 2, the .rear is 4, and there are currently 4 letters and 1 number in that queue. What happens when you perform the operation queue.Enqueue (letter); to add another char to that queue?
 
Snark aside, please do let us know when you're asking about homework. And that particular problem seems like something we can't help with much. I suggest you draw it out on paper and see what happens.
 
As Ken says, this is homework.

However, even if this wasn't homework, you wouldn't get a good answer as you haven't provided enough information.

What happens when you try to add to an empty queue? Depends on the queue implementation. Some will block until space is available. Some will return or throw some error status to indicate that the item wasn't added. Others will blast over the head of the queue (or even the tail of the queue!).

About the only behavior that I wouldn't expect is a middle insertion.
 
If you add something to a queue that is full, you should get an error condition, unless you just did a terrible job coding it.

Depends on the queue. Blocking might be acceptable, Head/Tail overwriting may also be acceptable. Just depends on what the queue was meant for.
 
It has a max queue of 5, declared position of having 4, yet stated that it has 5 items in it.

Contradictory queue is Contradictory
 
I should have stated that it is a homework question in the book. I just wanted some guidance on what would happen if the max said 5 but looking at the array in the question, there were 5 characters. The Enqueue operation that's trying to add another letter would, I thought, cause the overflow condition.
 
I should have stated that it is a homework question in the book. I just wanted some guidance on what would happen if the max said 5 but looking at the array in the question, there were 5 characters. The Enqueue operation that's trying to add another letter would, I thought, cause the overflow condition.

As said above, that depends on the implementation. What does the documentation for the library you are using say will happen? Error response, exception, memory access violation, overwritten entry, the always popular "behavior is undefined"? All are possibilities.
 
I should have stated that it is a homework question in the book. I just wanted some guidance on what would happen if the max said 5 but looking at the array in the question, there were 5 characters. The Enqueue operation that's trying to add another letter would, I thought, cause the overflow condition.

What have you tried? Can you provide some sample code? Most here know the answer, but no one here will help unless you show attempts at the problem.
 
Back
Top