Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/fathym_common/src/common/iterables/Stack.ts>Stack

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Latest
class Stack
import { Stack } from "https://deno.land/x/fathym_common@v0.2.160/src/common/iterables/Stack.ts";

This is a simple implementation of a stack data structure.

Examples

From direct import

import { Stack } from "@fathym/common/iterables";

const stack = new Stack<number>();

stack.Push(1);

stack.Push(2);

stack.Pop(); // Output: 2

stack.Peek(); // Output: 1

stack.Pop(); // Output: 1

stack.IsEmpty(); // Output: true

From common import

import { Stack } from "@fathym/common";

const stack = new Stack<number>();

stack.Push(1);

stack.Push(2);

stack.Pop(); // Output: 2

stack.Pop(); // Output: 1

Constructors

new
Stack()

Properties

private
items: T[]

Methods

IsEmpty(): boolean

Used to check if the stack is empty.

Peek(): T | undefined

Used to return the item at the top of the stack without removing it.

Pop(): T | undefined

Used to remove and return the item at the top of the stack.

Push(item: T): void

Used to add an item to the top of the stack.

Size(): number

Used to get the number of items in the stack.