Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Stack

Last in first out (LIFO) linear data structure

Example

const { Stack }  = require('dsajs');
// or
// import { Stack } from 'dsajs';

let s = new Stack();

Hierarchy

  • Stack

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Stack(arr?: any[]): Stack
  • throws

    Will throw an error if the argument is provided and is not an arry

    Parameters

    • arr: any[] = []

      optional array to initialize stack

    Returns Stack

Properties

Private _

_: any[]

to hold stack's data

Accessors

size

  • get size(): number
  • Get the number of elements in stack

    Returns number

    number of elements in stack

Methods

isEmpty

  • isEmpty(): boolean
  • Check if stack is empty

    Returns boolean

    true if stack is empty else false;

peek

  • peek(): any
  • Peek the top element of a stack without removing it from stack

    Returns any

    the last element of stack or undefined if stack is empty

pop

  • pop(): any
  • Returns the top element of stack

    Returns any

    the top element of stack or undefined if stack is empty

push

  • push(element: any): void

Generated using TypeDoc