# Stack | data-structure-typed
Documentation for data-structure-typed

# Class Stack<T>

#### License

MIT

#### Copyright

Tyler Zeng zrwusa@gmail.com

#### Type Parameters

- #### T = number

#### 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<T>(elements?): Stack <T>

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

  #### Type Parameters

  - #### T = number

  #### Parameters

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

    The `elements` parameter is an optional parameter of type `T[]`, which represents an array of elements of type `T`. 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 <T>

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

## Properties

### `Protected` _elements

_elements: T[]

- 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 <T>

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

  #### Returns Stack <T>

  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 | T

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

  #### Returns null | T

  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 | T

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

  #### Returns null | T

  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 <T>

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

  #### Parameters

  - ##### element: T

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

  #### Returns Stack <T>

  The `push` method is returning the updated `Stack<T>` 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(): T[]

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

  #### Returns T[]

  An array of type T.

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

### `Static` fromArray

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

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

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### elements: T[]

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

  #### Returns Stack <T>

  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