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

# LinkedStack

Container of elements that are inserted and removed according to the LIFO principle. This structure is based on SinglyLinkedList.

### new LinkedStack()

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

### length

```typescript
length: number
```

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

#### Examples:

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

const stack = new LinkedStack();

stack.length === 0; // true
stack.push(1);
stack.length === 1; // true
```

### clear()

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

### isEmpty()

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

> Running time O(1)

Checks whether the stack is empty or not.

#### Returns:

TRUE if the stack is empty, FALSE otherwise.

#### Examples:

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

const stack = new LinkedStack();

stack.isEmpty(); // true
stack.push(1);
stack.isEmpty(); // false
```

### pop()

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

### push()

```typescript
/**
 * Adds element at the top of the stack.
 *
 * @param element Element to add.
 */
push(element: T): void;
```

### top()

```typescript
/**
 * Gets element from the top of the stack without its removal.
 *
 * @returns Stack element.
 */
top(): T;
```
