# Class Stack<E>

#### License

MIT

#### Copyright

Tyler Zeng zrwusa@gmail.com

#### Type Parameters

- #### E = any

#### Hierarchy

- Stack

- Defined in src/data-structures/stack/stack.ts:6

#####
Index

### Constructors

constructor

### Properties

_elements

### Methods

clear
clone
isEmpty
peek
pop
push
size
toArray
fromArray

## Constructors

### constructor

- new Stack<E>(elements?): Stack<E>

- The constructor initializes an array of elements, which can be provided as an optional parameter.

  #### Type Parameters

  - #### E = any

  #### Parameters

  - ##### `Optional` elements: E[]

    The `elements` parameter is an optional parameter of type `E[]`, which represents an array of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter is provided and is an array, it is assigned to the `_elements

  #### Returns Stack<E>

  - Defined in src/data-structures/stack/stack.ts:15

## Properties

### `Protected` _elements

_elements: E[]

- Defined in src/data-structures/stack/stack.ts:7

## Methods

### clear

- clear(): void

- The clear function clears the elements array.

  #### Returns void

  - Defined in src/data-structures/stack/stack.ts:87

### clone

- clone(): Stack<E>

- The `clone()` function returns a new `Stack` object with the same elements as the original stack.

  #### Returns Stack<E>

  The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.

  - Defined in src/data-structures/stack/stack.ts:95

### isEmpty

- isEmpty(): boolean

- The function checks if an array is empty and returns a boolean value.

  #### Returns boolean

  A boolean value indicating whether the `_elements` array is empty or not.

  - Defined in src/data-structures/stack/stack.ts:33

### peek

- peek(): null | E

- The `peek` function returns the last element of an array, or null if the array is empty.

  #### Returns null | E

  The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.

  - Defined in src/data-structures/stack/stack.ts:49

### pop

- pop(): null | E

- The `pop` function removes and returns the last element from an array, or returns null if the array is empty.

  #### Returns null | E

  The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the array is empty, it returns `null`.

  - Defined in src/data-structures/stack/stack.ts:70

### push

- push(element): Stack<E>

- The push function adds an element to the stack and returns the updated stack.

  #### Parameters

  - ##### element: E

    The parameter "element" is of type E, which means it can be any data type.

  #### Returns Stack<E>

  The `push` method is returning the updated `Stack<E>` object.

  - Defined in src/data-structures/stack/stack.ts:60

### size

- size(): number

- The size() function returns the number of elements in an array.

  #### Returns number

  The size of the elements array.

  - Defined in src/data-structures/stack/stack.ts:41

### toArray

- toArray(): E[]

- The toArray function returns a copy of the elements in an array.

  #### Returns E[]

  An array of type E.

  - Defined in src/data-structures/stack/stack.ts:80

### `Static` fromArray

- fromArray<E>(elements): Stack<E>

- The function "fromArray" creates a new Stack object from an array of elements.

  #### Type Parameters

  - #### E

  #### Parameters

  - ##### elements: E[]

    The `elements` parameter is an array of elements of type `E`.

  #### Returns Stack<E>

  The method is returning a new instance of the Stack class, initialized with the elements from the input array.

  - Defined in src/data-structures/stack/stack.ts:25

Generated using TypeDoc