RUVIDEO
Поделитесь видео 🙏

Priority Queue - Constructor

Video #2 within the Priority Queue Series

Transcript:
Previously, we learned about what Priority Queues are and what makes them special. They give us automatic ordering without explicit sorting. Now, we will learn about creating a Priority Queue in Java.

Creating a priority queue with an empty constructor will get you this default ordering; if you want a custom ordering, you can pass a custom comparator in the constructor like this; you will also have to specify an initial capacity. For example, if you want the elements ordered in descending order, you can call the Collections.reverseOrder() method to receive a descending order comparator object you can then pass to the priority queue constructor. Finally, you can create a priority queue that contains the elements of another collection-type object, as seen here. When writing your constructor, you will also have to specify the type of object you plan to store in the queue.

Behind the scenes, the built-in Java priority queue implementation is backed by a priority heap. As a result, adding and polling elements both take O(log(n)) time, while peeking is O(1) since no reorganization of the heap is required.

Some of the commonly used methods, available to the priority queue data structure, are add(), peek(), comparator(), remove(), clear(), poll(), and toArray(). We will look at these methods in the next video.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Priority Queue - Constructor», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.