|
The priority queue defaults to form a lot of piles
|
bet | 6/9 | Sana | 24.05.2024 | Hajmi | 0,71 Mb. | | #252108 |
Bog'liq Nishonova G (D2 M2)The priority queue defaults to form a lot of piles
The element of the priority queue is popped up from the top, and the top is the highest priority.
The underlying container can be a class template for any container, or other specific design container classes (designed), the function supported by the container: random access Operator [], EMPTY, SIZE, Front, Push_Back, Pop_Front.
Standard containers VECTOR and DEQUE can meet these needs, priority queues when they do not display the definition container templateUse Vector by default.
Priority queues use the imitation function to control the generated large root stack or generate a small root heap.
Brief introduction to the imitation function:
Imitation function (functor) is also called function object is a class that can exercise function functions. The syntax of the imitation function is almost the same as our ordinary function call, but as the class of the imitation function, the Operator () operator must be overloaded. Because calling the imitation function, it is actually called the Operator () operator after being called by the class object.The imitation function is a class, just like a function. Wait until the simulation is implemented.
4.2 Priority_Queue Used
The priority queue defaults to the container of storage data by default, using a heap algorithm based on the container, adjusting the elements in the vector into a stack structure.
Note: The priority queue is a heap that you can use the priority queue in places where you are using.By default, large roots are generated, and the header file is also #include
function
|
Features
|
priority_queue()
|
Create an empty priority queue
|
priority_queue(first,last)
|
Building an iterator first to the elements between Last
|
top
|
Returns the highest level of priority in the priority queue, the top elements
|
size
|
Returns the number of elements in the prior queue
|
empty
|
Judging whether the priority queue is empty
|
push
|
Insert the element into the priority queue
|
pop
|
Delete the highest priority in the priority queue, ie pile elements
|
Note: If you put the type of data in Priority_Queue, it is necessary to place the operator overload in the container of the stored data, because adjustment of the heap.
|
| |