# Class SinglyLinkedList<E>

#### Type Parameters

- #### E = any

#### Hierarchy

- SinglyLinkedList
  - LinkedListQueue

- Defined in src/data-structures/linked-list/singly-linked-list.ts:40

#####
Index

### Constructors

constructor

### Properties

_head
_length
_tail

### Accessors

head
length
tail

### Methods

[iterator]
clear
countOccurrences
delete
deleteAt
find
findNode
getAt
getLength
getNodeAt
indexOf
insertAfter
insertAt
insertBefore
isEmpty
pop
push
reverse
shift
toArray
unshift
fromArray

## Constructors

### constructor

- new SinglyLinkedList<E>(): SinglyLinkedList<E>

- The constructor initializes the linked list with an empty head, tail, and length.

  #### Type Parameters

  - #### E = any

  #### Returns SinglyLinkedList<E>

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:44

## Properties

### `Private` _head

_head: null | SinglyLinkedListNode<E>

- Defined in src/data-structures/linked-list/singly-linked-list.ts:50

### `Private` _length

_length: number

- Defined in src/data-structures/linked-list/singly-linked-list.ts:70

### `Private` _tail

_tail: null | SinglyLinkedListNode<E>

- Defined in src/data-structures/linked-list/singly-linked-list.ts:60

## Accessors

### head

- get head(): null | SinglyLinkedListNode<E>

- #### Returns null | SinglyLinkedListNode<E>

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:52
- set head(value): void

- #### Parameters

  - ##### value: null | SinglyLinkedListNode<E>

  #### Returns void

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:56

### length

- get length(): number

- #### Returns number

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:72

### tail

- get tail(): null | SinglyLinkedListNode<E>

- #### Returns null | SinglyLinkedListNode<E>

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:62
- set tail(value): void

- #### Parameters

  - ##### value: null | SinglyLinkedListNode<E>

  #### Returns void

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:66

## Methods

### [iterator]

- [iterator](): Generator<E, void, unknown>

- #### Returns Generator<E, void, unknown>

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:493

### clear

- clear(): void

- The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.

  #### Returns void

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:300

### countOccurrences

- countOccurrences(value): number

- The function counts the number of occurrences of a given value in a linked list.

  #### Parameters

  - ##### value: E

    The value parameter is the value that you want to count the occurrences of in the linked list.

  #### Returns number

  The count of occurrences of the given value in the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:479

### delete

- delete(valueOrNode): boolean

- The delete function removes a node with a specific value from a singly linked list.

  #### Parameters

  - ##### valueOrNode: E

    The `valueOrNode` parameter can accept either a value of type `E` or a `SinglyLinkedListNode<E>` object.

  #### Returns boolean

  The `delete` method returns a boolean value. It returns `true` if the value or node is found and successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:217
- delete(valueOrNode): boolean

- The delete function removes a node with a specific value from a singly linked list.

  #### Parameters

  - ##### valueOrNode: SinglyLinkedListNode<E>

    The `valueOrNode` parameter can accept either a value of type `E` or a `SinglyLinkedListNode<E>` object.

  #### Returns boolean

  The `delete` method returns a boolean value. It returns `true` if the value or node is found and successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:218

### deleteAt

- deleteAt(index): undefined | E

- The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.

  #### Parameters

  - ##### index: number

    The index parameter represents the position of the element that needs to be deleted in the data structure. It is of type number.

  #### Returns undefined | E

  The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:205

### find

- find(callback): null | E

- The `find` function iterates through a linked list and returns the first element that satisfies a given condition.

  #### Parameters

  - ##### callback: ((val) => boolean)

    A function that takes a value of type E as its parameter and returns a boolean value. This function is used to determine whether a particular value in the linked list satisfies a certain condition.

    - - (val): boolean

      - #### Parameters

        - ##### val: E

        #### Returns boolean

  #### Returns null | E

  The method `find` returns the first element in the linked list that satisfies the condition specified by the callback function. If no element satisfies the condition, it returns `null`.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:348

### findNode

- findNode(value): null | SinglyLinkedListNode<E>

- The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns null.

  #### Parameters

  - ##### value: E

    The value parameter is the value that we want to search for in the linked list.

  #### Returns null | SinglyLinkedListNode<E>

  a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with the specified value is found, the function returns `null`.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:387

### getAt

- getAt(index): undefined | E

- The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.

  #### Parameters

  - ##### index: number

    The index parameter is a number that represents the position of the element we want to retrieve from the list.

  #### Returns undefined | E

  The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or `null` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:174

### getLength

- getLength(): number

- #### Returns number

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:90

### getNodeAt

- getNodeAt(index): null | SinglyLinkedListNode<E>

- The function `getNodeAt` returns the node at a given index in a singly linked list.

  #### Parameters

  - ##### index: number

    The `index` parameter is a number that represents the position of the node we want to retrieve from the linked list. It indicates the zero-based index of the node we want to access.

  #### Returns null | SinglyLinkedListNode<E>

  The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the specified index exists, or `null` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:190

### indexOf

- indexOf(value): number

- The `indexOf` function returns the index of the first occurrence of a given value in a linked list.

  #### Parameters

  - ##### value: E

    The value parameter is the value that you want to find the index of in the linked list.

  #### Returns number

  The method is returning the index of the first occurrence of the specified value in the linked list. If the value is not found, it returns -1.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:365

### insertAfter

- insertAfter(existingValueOrNode, newValue): boolean

- The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.

  #### Parameters

  - ##### existingValueOrNode: E

    The existing value or node in the linked list after which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The value that you want to insert into the linked list after the existing value or node.

  #### Returns boolean

  The method returns a boolean value. It returns true if the new value was successfully inserted after the existing value or node, and false if the existing value or node was not found in the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:440
- insertAfter(existingValueOrNode, newValue): boolean

- The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.

  #### Parameters

  - ##### existingValueOrNode: SinglyLinkedListNode<E>

    The existing value or node in the linked list after which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The value that you want to insert into the linked list after the existing value or node.

  #### Returns boolean

  The method returns a boolean value. It returns true if the new value was successfully inserted after the existing value or node, and false if the existing value or node was not found in the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:441

### insertAt

- insertAt(index, val): boolean

- The `insertAt` function inserts a value at a specified index in a singly linked list.

  #### Parameters

  - ##### index: number

    The index parameter represents the position at which the new value should be inserted in the linked list. It is of type number.

  - ##### val: E

    The `val` parameter represents the value that you want to insert into the linked list at the specified index.

  #### Returns boolean

  The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:269

### insertBefore

- insertBefore(existingValue, newValue): boolean

- The `insertBefore` function inserts a new value before an existing value in a singly linked list.

  #### Parameters

  - ##### existingValue: E

  - ##### newValue: E

    The `newValue` parameter represents the value that you want to insert into the linked list.

  #### Returns boolean

  The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully inserted before the existing value, and `false` otherwise.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:400
- insertBefore(existingValue, newValue): boolean

- The `insertBefore` function inserts a new value before an existing value in a singly linked list.

  #### Parameters

  - ##### existingValue: SinglyLinkedListNode<E>

  - ##### newValue: E

    The `newValue` parameter represents the value that you want to insert into the linked list.

  #### Returns boolean

  The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully inserted before the existing value, and `false` otherwise.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:401

### isEmpty

- isEmpty(): boolean

- The function checks if the length of a data structure is equal to zero and returns a boolean value indicating whether it is empty or not.

  #### Returns boolean

  A boolean value indicating whether the length of the object is equal to 0.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:293

### pop

- pop(): undefined | E

- The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail pointers accordingly.

  #### Returns undefined | E

  The method `pop()` returns the value of the node that is being removed from the end of the linked list. If the linked list is empty, it returns `null`.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:117

### push

- push(data): void

- The `push` function adds a new node with the given data to the end of a singly linked list.

  #### Parameters

  - ##### data: E

    The "data" parameter represents the value that you want to add to the linked list. It can be of any type (E) as specified in the generic type declaration of the class or function.

  #### Returns void

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:99

### reverse

- reverse(): void

- The `reverse` function reverses the order of the nodes in a singly linked list.

  #### Returns void

  The reverse() method does not return anything. It has a return type of void.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:324

### shift

- shift(): undefined | E

- The `shift()` function removes and returns the value of the first node in a linked list.

  #### Returns undefined | E

  The value of the node that is being removed from the beginning of the linked list.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:142

### toArray

- toArray(): E[]

- The `toArray` function converts a linked list into an array.

  #### Returns E[]

  The `toArray()` method is returning an array of type `E[]`.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:310

### unshift

- unshift(val): void

- The unshift function adds a new node with the given value to the beginning of a singly linked list.

  #### Parameters

  - ##### val: E

    The parameter "val" represents the value of the new node that will be added to the beginning of the linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:155

### `Static` fromArray

- fromArray<E>(data): SinglyLinkedList<E>

- The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given array.

  #### Type Parameters

  - #### E

  #### Parameters

  - ##### data: E[]

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

  #### Returns SinglyLinkedList<E>

  The `fromArray` function returns a `SinglyLinkedList` object.

  - Defined in src/data-structures/linked-list/singly-linked-list.ts:82

Generated using TypeDoc