C++ question

Ordy

Member
Nov 21, 2004
25
0
0
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?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,284
3,905
75
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.
 
Feb 25, 2011
16,823
1,493
126
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.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
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.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
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.
 

Schmide

Diamond Member
Mar 7, 2002
5,590
724
126
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
 

Ordy

Member
Nov 21, 2004
25
0
0
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.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
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.
 

uclabachelor

Senior member
Nov 9, 2009
448
0
71
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |