Java очередь с приоритетами

Class PriorityQueue

An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException ).

The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements — ties are broken arbitrarily. The queue retrieval operations poll , remove , peek , and element access the element at the head of the queue.

A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified.

This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() and the Spliterator provided in method spliterator() are not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()) .

Note that this implementation is not synchronized. Multiple threads should not access a PriorityQueue instance concurrently if any of the threads modifies the queue. Instead, use the thread-safe PriorityBlockingQueue class.

Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods ( offer , poll , remove() and add ); linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods ( peek , element , and size ).

This class is a member of the Java Collections Framework.

Источник

Java очередь с приоритетами

An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException ). The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements — ties are broken arbitrarily. The queue retrieval operations poll , remove , peek , and element access the element at the head of the queue. A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified. This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()) . Note that this implementation is not synchronized. Multiple threads should not access a PriorityQueue instance concurrently if any of the threads modifies the queue. Instead, use the thread-safe PriorityBlockingQueue class. Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods ( offer , poll , remove() and add ); linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods ( peek , element , and size ). This class is a member of the Java Collections Framework.

Читайте также:  Https informatics msk ru course view php id 156

Constructor Summary

Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

Creates a PriorityQueue with the default initial capacity and whose elements are ordered according to the specified comparator.

Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering.

Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

Method Summary

Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.

Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.

Methods inherited from class java.util.AbstractQueue

Methods inherited from class java.util.AbstractCollection

Methods inherited from class java.lang.Object

Methods inherited from interface java.util.Collection

Methods inherited from interface java.lang.Iterable

Constructor Detail

PriorityQueue

Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

PriorityQueue

public PriorityQueue(int initialCapacity)

Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering.

PriorityQueue

Creates a PriorityQueue with the default initial capacity and whose elements are ordered according to the specified comparator.

PriorityQueue

Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

PriorityQueue

Creates a PriorityQueue containing the elements in the specified collection. If the specified collection is an instance of a SortedSet or is another PriorityQueue , this priority queue will be ordered according to the same ordering. Otherwise, this priority queue will be ordered according to the natural ordering of its elements.

Читайте также:  Inurl administrator login php

PriorityQueue

Creates a PriorityQueue containing the elements in the specified priority queue. This priority queue will be ordered according to the same ordering as the given priority queue.

PriorityQueue

Creates a PriorityQueue containing the elements in the specified sorted set. This priority queue will be ordered according to the same ordering as the given sorted set.

Источник

Java очередь с приоритетами

An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException ). The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements — ties are broken arbitrarily. The queue retrieval operations poll , remove , peek , and element access the element at the head of the queue. A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified. This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() and the Spliterator provided in method spliterator() are not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()) . Note that this implementation is not synchronized. Multiple threads should not access a PriorityQueue instance concurrently if any of the threads modifies the queue. Instead, use the thread-safe PriorityBlockingQueue class. Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods ( offer , poll , remove() and add ); linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods ( peek , element , and size ). This class is a member of the Java Collections Framework.

Читайте также:  Java io utfdataformatexception malformed input around byte 2

Constructor Summary

Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering.

Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

Creates a PriorityQueue with the default initial capacity and whose elements are ordered according to the specified comparator.

Method Summary

Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Removes all of this collection’s elements that are also contained in the specified collection (optional operation).

Retains only the elements in this collection that are contained in the specified collection (optional operation).

Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.

Methods declared in class java.util.AbstractQueue

Methods declared in class java.util.AbstractCollection

Methods declared in class java.lang.Object

Methods declared in interface java.util.Collection

Methods declared in interface java.util.Queue

Constructor Detail

PriorityQueue

Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

PriorityQueue

public PriorityQueue​(int initialCapacity)

Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering.

PriorityQueue

Creates a PriorityQueue with the default initial capacity and whose elements are ordered according to the specified comparator.

PriorityQueue

Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

PriorityQueue

Creates a PriorityQueue containing the elements in the specified collection. If the specified collection is an instance of a SortedSet or is another PriorityQueue , this priority queue will be ordered according to the same ordering. Otherwise, this priority queue will be ordered according to the natural ordering of its elements.

PriorityQueue

Creates a PriorityQueue containing the elements in the specified priority queue. This priority queue will be ordered according to the same ordering as the given priority queue.

PriorityQueue

Creates a PriorityQueue containing the elements in the specified sorted set. This priority queue will be ordered according to the same ordering as the given sorted set.

Источник

Оцените статью