Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 2 Question 77 Discussion

Posted by Colette on Jan 27, 2024 at 10:52 PM

Which are NOT valid instantiations of priority_queue object:

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;list mylist; vector myvector;

priority_queue first;//line I

priority_queue > second;//line II

priority_queue third(first);//line III

priority_queue > fourth(third);//line IV

priority_queue > fifth(myvector.begin(), myvector.end());//line V

return 0;

}

Suggested Answer: E

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
46 comments · newest first
CA
Caprice 11 months ago
Definitely line IV, lists can't be used like that!
CA
Carri 11 months ago
Wait, can you really use a list in a priority_queue?
QU
Quentin 11 months ago
Line II is good too, deque works with priority_queue.
TA
Tambra 11 months ago
I think line IV is the one that's not valid.
BR
Brigette 11 months ago
Line III is valid, just a copy constructor.
LE
Lettie 12 months ago
I practiced a similar question, and I think line V is fine because it uses a vector, which is a valid underlying container for a priority queue.
AV
Avery 12 months ago
Line IV seems off to me; I don't recall if you can instantiate a priority queue with another priority queue as a parameter.
CA
Carmelina 12 months ago
I remember something about the container types for priority queues, and I feel like line II is valid since deque is one of the allowed types.
RO
Rosio 1 year ago
I think line III might be problematic because it looks like it's trying to copy a priority queue, but I'm not sure if that's allowed.
ER
Erin 1 year ago
This looks like a tricky question, but I think I can figure it out. I'll need to carefully consider the valid container types for priority_queue and how they interact with the provided examples.
BU
Bulah 1 year ago
I'm a bit confused by the different container types being used here. I'll need to refresh my memory on the requirements for the priority_queue constructor and make sure I understand the differences between these containers.
CH
Christa 1 year ago
I think I know the answer to this one. The priority_queue container requires a specific type of underlying container, and not all of these options are valid. I'll need to double-check the details, but I'm feeling confident about this.
AL
Alton 1 year ago
Okay, let me see. The first line seems straightforward, but the others might have some restrictions I'm not sure about. I'll have to review the priority_queue documentation to be sure.
LA
Lashawna 1 year ago
Hmm, this looks tricky. I'll need to carefully read through the code and think about the requirements for a valid priority_queue instantiation.
BO
Bong 1 year ago
This question seems straightforward, I'm pretty confident I can figure it out.
WI
Winifred 1 year ago
I think the key here is to focus on the idea of consistency. Consistent service means treating all customers the same way, so the priority assignment should be based on a standardized agreement, not individual factors. I'm leaning towards option C, but I'll double-check the other choices just to be sure.
ZA
Zack 1 year ago
I'm torn between A and B because it could be tricky. Were there some conditions in the script that might lead to only nine objects being created instead?
MA
Malcom 1 year ago
I'm pretty sure all the other lines are valid instantiations. Line IV is the only one that doesn't work. Now, if they asked me to instantiate a priority_queue with a banana, that would be a different story!
SH
Shawnda 1 year ago
↳ replying to Malcom
I agree with you, line IV is the only one that doesn't work. The rest are valid instantiations.
MA
Mary 1 year ago
↳ replying to Malcom
No, I'm pretty confident that line II is valid. It's line IV that doesn't work.
ST
Stephaine 1 year ago
↳ replying to Malcom
Are you sure about that? I think line II is also not a valid instantiation.
TI
Timothy 1 year ago
↳ replying to Malcom
E) line V
AN
Antonio 1 year ago
↳ replying to Malcom
D) line IV
RA
Raina 1 year ago
↳ replying to Malcom
C) line III
MA
Margarita 1 year ago
↳ replying to Malcom
B) line II
MA
Mattie 1 year ago
↳ replying to Malcom
A) line I
CY
Cyril 1 year ago
Haha, it's funny how they try to trick us with a list. Who uses a list for a priority queue? That's like trying to use a toaster to dry your hair!
EU
Eun 1 year ago
↳ replying to Cyril
It's like using a toaster to dry your hair, totally useless!
LA
Lavonne 1 year ago
↳ replying to Cyril
C) line III
PA
Paris 1 year ago
↳ replying to Cyril
I agree, a list is not efficient for a priority queue.
IR
Irma 1 year ago
↳ replying to Cyril
Definitely! A priority queue should be implemented with a deque or a vector.
BU
Buck 1 year ago
↳ replying to Cyril
Haha, I know right! Using a list for a priority queue is a bad idea.
PA
Pamela 1 year ago
↳ replying to Cyril
B) line II
LY
Lyda 1 year ago
↳ replying to Cyril
A) line I
CA
Carissa 2 years ago
I believe line V is also not valid because it is trying to initialize a priority_queue with iterators from a vector.
LA
Lauran 2 years ago
I agree with Van, line I is incorrect because it is missing the container type.
VA
Van 2 years ago
I think line I is not a valid instantiation.
MA
Maynard 2 years ago
I agree with Mabel. The list is not a valid container for a priority_queue, so line IV is not a valid instantiation.
CE
Cecily 1 year ago
↳ replying to Maynard
That makes sense. Thanks for clarifying!
SH
Sherrell 1 year ago
↳ replying to Maynard
So, the correct answer would be D) line IV.
BE
Beckie 1 year ago
↳ replying to Maynard
Yes, I agree. The correct containers for priority_queue are deque and vector.
MA
Marget 1 year ago
↳ replying to Maynard
I think line IV is not valid because list is not a valid container for priority_queue.
CA
Carmela 2 years ago
I believe line V is also not valid because it is trying to initialize a priority_queue with iterators from a vector.
DA
Darrin 2 years ago
I agree with Willetta, line I is incorrect because it is missing the container type.
MA
Mabel 2 years ago
The correct answer is line IV. A priority_queue can only be instantiated with a deque or a vector as the underlying container, not a list.
WI
Willetta 2 years ago
I think line I is not a valid instantiation.
0/2000 characters

Save Cancel