Skip to content

Latest commit

 

History

History
330 lines (181 loc) · 6.65 KB

Stack.md

File metadata and controls

330 lines (181 loc) · 6.65 KB

circle-ds / Exports / Stack

Interface: Stack<V>

Represents a stack collection of elements. A stack allows elements to be added and removed from the end of the collection only, following the LIFO (Last In, First Out) principle. This interface extends the Collection interface and specifies additional stack-specific operations.

Stacks are commonly used in scenarios where you need to temporarily store and retrieve elements in a reverse order of their addition, such as in undo mechanisms, parsing algorithms, and temporary buffers.

Type parameters

Name
V

Hierarchy

Implemented by

Table of contents

Accessors

Methods

Accessors

[toStringTag]

get [toStringTag](): string

A string tag for the Collection class that is used in Object.prototype.toString.

Returns

string

Inherited from

Collection.[toStringTag]

Defined in

types/collection.d.ts:19


size

get size(): number

Gets the number of elements contained in the Collection.

Returns

number

Inherited from

Collection.size

Defined in

types/collection.d.ts:14

Methods

[iterator]

[iterator](): IterableIterator<V>

Returns the default iterator through the stack's elements.

Returns

IterableIterator<V>

Defined in

types/stack.d.ts:50


clear

clear(): void

Removes all elements from the Collection, effectively resetting it.

Returns

void

Inherited from

Collection.clear

Defined in

types/collection.d.ts:24


entries

entries(): IterableIterator<[number, V]>

Returns a new iterator object that contains an array of [key, value] pairs for each element in the Collection.

Returns

IterableIterator<[number, V]>

An iterable iterator for the entries of the collection.

Inherited from

Collection.entries

Defined in

types/collection.d.ts:32


forEach

forEach(callbackfn, thisArg?): void

Executes a provided function once for each key-value pair in the Collection.

Parameters

Name Type Description
callbackfn (value: V, key: number, collection: this) => void A function to execute for each element, receiving the value, key, and collection instance as arguments.
thisArg? unknown An optional value to use as this when executing callbackfn.

Returns

void

Inherited from

Collection.forEach

Defined in

types/collection.d.ts:41


has

has(value): boolean

Determines whether an element exists within the stack.

Parameters

Name Type Description
value V The value to locate.

Returns

boolean

true if the value exists, 'false' otherwise.

Defined in

types/stack.d.ts:21


keys

keys(): IterableIterator<number>

Returns a new iterator that contains the keys for each element in the Collection.

Returns

IterableIterator<number>

An iterable iterator for the keys of the collection.

Inherited from

Collection.keys

Defined in

types/collection.d.ts:52


last

last(): undefined | V

Retrieves the last element added to the stack without removing it.

Returns

undefined | V

The last element of the stack, or undefined if the stack is empty.

Defined in

types/stack.d.ts:28


pop

pop(): undefined | V

Removes the last element added to the stack and returns it.

Returns

undefined | V

The last element of the stack, or undefined if the stack is empty.

Defined in

types/stack.d.ts:35


push

push(...values): number

Adds one or more elements to the end of the stack and returns the stack's new length.

Parameters

Name Type Description
...values V[] The elements to add.

Returns

number

The new length of the stack.

Defined in

types/stack.d.ts:45


top

top(): undefined | V

Retrieves the element at the top of the stack without removing it.

This method provides semantic clarity in contexts where the term "top" is preferred over "last" to describe the most recently added element.

Returns

undefined | V

The element at the top of the stack, or undefined if the stack is empty.

Defined in

types/stack.d.ts:60


values

values(): IterableIterator<V>

Returns a new iterator that contains the values for each element in the Collection.

Returns

IterableIterator<V>

An iterable iterator for the values of the collection.

Inherited from

Collection.values

Defined in

types/collection.d.ts:60