> 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/linkeddeque.md).

# LinkedDeque

Container of elements that are inserted and removed on either side. This structure is based on DoublyLinkedList.

### new LinkedDeque()

```typescript
/**
 * Creates an instance of LinkedDeque.
 *
 * @param elements List of elements to create the new queue with.
 */
constructor(elements: T[] = [])
```

### length

```typescript
length: number
```

Number of elements in the queue. This field is read only.

#### Examples:

```typescript
import { LinkedDeque } from 'ads-js/queues';

const queue = new LinkedDeque();

queue.length === 0; // true
queue.enqueue(1);
queue.length === 1; // true
```

### clear()

```typescript
/**
 * Clears the queue.
 */
clear(): void;
```

### dequeue()

```typescript
/**
 * Removes the first element from the front of the queue and returns it.
 * Throws an error if the queue is empty.
 *
 * @returns Removed element.
 */
dequeue(): T;
```

### dequeLast()

```typescript
/**
 * Removes the last element from the rear of the queue and returns it. Throws an error if the queue is empty.
 *
 * @returns Removed element.
 */
dequeueLast(): T;
```

### enqueue()

```typescript
/**
 * Adds element at the rear of the queue.
 *
 * @param element Element to add.
 */
enqueue(element: T): void;
```

### enqueueFirst()

```typescript
/**
 * Adds element at the front of the queue.
 *
 * @param element Element to add.
 */
enqueueFirst(element: T): void;
```

### getFirst()

```typescript
/**
 * Gets element from the front of the queue without its removal.
 *
 * @returns Queue element.
 */
getFirst(): T;
```

### getLast()

```typescript
/**
 * Gets element from the rear of the queue without its removal.
 *
 * @returns Queue element.
 */
getLast(): T;
```

### isEmpty()

```typescript
isEmpty(): boolean
```

> Running time O(1)

Checks whether the queue is empty or not.

#### Returns:

TRUE if the queue is empty, FALSE otherwise.

#### Examples:

```typescript
import { LinkedDeque } from 'ads-js/queues';

const queue = new LinkedDeque();

queue.isEmpty(); // true
queue.enqueue(1);
queue.isEmpty(); // false
```
