Stacks and queues can be implemented as particular kinds of priority queues, with the priority determined by the order in which the elements are inserted. More advanced implementations may support more complicated operations, such as pull_lowest_priority_element, inspecting the first few highest- or lowest-priority elements, clearing the queue, clearing subsets of the queue, performing a batch insert, merging two or more queues into one, incrementing priority of any element, etc. This operation and its O(1) performance is crucial to many applications of priority queues. In addition, peek (in this context often called find-max or find-min), which returns the highest-priority element but does not modify the queue, is very frequently implemented, and nearly always executes in O(1) time. This may instead be specified as separate " peek_at_highest_priority_element" and " delete_element" functions, which can be combined to produce " pull_highest_priority_element". Some conventions reverse the order of priorities, considering lower values to be higher priority, so this may also be known as " get_minimum_element", and is often referred to as " get-min" in the literature. This is also known as " pop_element(Off)", " get_maximum_element" or " get_front(most)_element". pull_highest_priority_element: remove the element from the queue that has the highest priority, and return it.insert_with_priority: add an element to the queue with an associated priority.is_empty: check whether the queue has no elements. A priority queue is an abstract data structure like a list or a map just as a list can be implemented with a linked list or with an array, a priority queue can be implemented with a heap or another method such as an unordered array.Ī priority queue must at least support the following operations: While priority queues are often implemented using heaps, they are conceptually distinct from heaps. In other implementations, the order of elements with the same priority is undefined. In some implementations, if two elements have the same priority, they are served in the same order in which they were enqueued. In a priority queue, elements with high priority are served before elements with low priority. Each element in a priority queue has an associated priority. #if _MSC_VER > 1020 // if VC++ version is > 4.In computer science, a priority queue is an abstract data-type similar to a regular queue or stack data structure. Copyright (c) 1996 Microsoft Corporation. of Microsoft Product Support Services, priority_queue::empty(), priority_queue::top(), queue::size() priority_queue::push(), priority_queue::pop(), L'esempio mostra priority_queuel'implementazione tramite deque contenitori e vector. Sme è stato modificato per migliorare la leggibilità. I nomi di classe/parametro nel prototipo potrebbero non corrispondere alla versione nel file di intestazione. L'elemento superiore diventa quindi il candidato di scelta, più basso o più alto in base alla funzione scelta. Priority_queue consente di gestire una raccolta ordinata di elementi determinata da una funzione di confronto associata, ad esempio minore, maggiore e così via. Poiché gli adapter non supportano l'iterazione, priority_queue a non è associato alcun iteratore. top() restituisce l'elemento principale nell'oggetto priority_queue. Gli oggetti vengono inseriti da push() e rimossi da pop(). I due contenitori supportati sono e vector deque. L'adapter priority_queue contiene oggetti del tipo definito dal tipo di contenitore supportato da priority_queue. Il codice di esempio seguente illustra come usare le priority_queue::pushfunzioni, priority_queue::pop, priority_queue::empty, priority_queue::tope priority_queue::size STL in Visual C++. Versione originale del prodotto: Visual C++ Numero KB originale: 157623 Riepilogo Questo articolo illustra come risolvere il problema relativo all'uso delle priority_queue::pushfunzioni, priority_queue::pop, priority_queue::empty, priority_queue::tope priority_queue::size STL in Visual C++.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |