17.2 Queues

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2551d899-da7f-4013-8a2c-254172e57e8c/Untitled.png

In the above picture, we observe that elements are first pushed to the back of the queue, and then the elements are removed through the front. Java’s implementation of queue also supports array operations including get() and indexOf(). This however means that insertion and eviction operations are much slower than if implemented using a simple linked list. For instance, C++ offers significant advantages over Java’s implementation, but Java’s implementation also has its advantages.

Regardless, below is a brief overview of the methods used in Java:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ded127fa-f18c-44e6-90e5-56ada2148cf3/Untitled.png

We observe here that the argument type is called E which is unique to Java, employing something called Java Generics. I will not talk too much about this further, but it is somewhat similar to C++’s template parameters (and for those who are curious, templates is one of the most powerful tools in C++, allowing users to do some really crazy stuff like partial template specialization). What this allows the user to do is define the type of objects which the queue contains. For now, pretend that E is replaced by the Integer type in the Java SE library.'

Previous Section

17.1 What are they?

Next Section

17.3 Stacks

<aside> ⚖️ Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License.

If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact [email protected] for inquiries.

</aside>