> For the complete documentation index, see [llms.txt](https://alex-myznikov.gitbook.io/adsjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alex-myznikov.gitbook.io/adsjs/api/stacks-and-queues.md).

# Stacks and queues

Import alias `'ads-js/queues'`

This group contains data structures based on ordinary JavaScript [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) as well as on [linked lists](/adsjs/api/linked-lists.md) from this package. Most of them are focused primarily on direct access to the stored elements without adapters akin [Position](/adsjs/api/position.md). The only structure which still uses [Locators](/adsjs/api/locator.md) is [AdaptableHeapPriorityQueue](/adsjs/api/stacks-and-queues/adaptableheappriorityqueue.md).

### Table of contents

[LinkedStack](/adsjs/api/stacks-and-queues/linkedstack.md) - container of elements that are inserted and removed according to the LIFO principle. This structure is based on SinglyLinkedList.

[LinkedQueue](/adsjs/api/stacks-and-queues/linkedqueue.md) - container of elements that are inserted and removed according to the FIFO principle. This structure is based on SinglyLinkedList.

[LinkedDeque](/adsjs/api/stacks-and-queues/linkeddeque.md) - container of elements that are inserted and removed on either side. This structure is based on DoublyLinkedList.

[CircularQueue](/adsjs/api/stacks-and-queues/circularqueue.md) - container of elements in which operations are performed based on FIFO principle and the last position is connected back to the first position to make a circle. This structure is based on CircularlyLinkedList.

[CircularArrayBuffer](/adsjs/api/stacks-and-queues/circulararraybuffer.md) - array-based implementation of circular FIFO data structure.

[UnsortedPriorityQueue](/adsjs/api/stacks-and-queues/unsortedpriorityqueue.md) - container of elements which grants access to the least item stored in linear time and takes constant time for insertion. This structure is based on DoublyLinkedList.

[SortedPriorityQueue](/adsjs/api/stacks-and-queues/sortedpriorityqueue.md) - container of elements which grants access to the least item stored in constant time and takes linear time for insertion. This structure is based on DoublyLinkedList.

[AdaptableHeapPriorityQueue](/adsjs/api/stacks-and-queues/adaptableheappriorityqueue.md) - container of elements which grants access to the least item stored in logarithmic time. Insertion operation has logarithmic complexity as well. This structure is based on binary heap and can afford constant time insertion if all queued elements are given in advance. It also allows to update elements after insertion and keeps itself sorted.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alex-myznikov.gitbook.io/adsjs/api/stacks-and-queues.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
