Stack

Stack

Class representing a Stack.

Constructor

new Stack(data)

Version:
  • v1.0

Create a stack.

Parameters:
Name Type Default Description
data null | Object null

The data is iterable object.

Methods

top() → {boolean|*}

Get the top data.

Returns:

false if the stack has no element else top element.

Type
boolean | *

empty() → {boolean}

Check the stack is empty.

Returns:

true if the stack is empty.

Type
boolean

size() → {number}

Get the number of elements in stack.

Returns:

the number of elements.

Type
number

clear()

Initialize Stack

push(data)

Push a data in stack.

Parameters:
Name Type Description
data *

The data pushed to stack.

pop() → {boolean}

pop the top elements

Returns:

false if the stack is empty.

Type
boolean

compare(otherStack) → {boolean}

compare with other stack

Parameters:
Name Type Description
otherStack Object

Stack object to compare.

Returns:

true if they are same.

Type
boolean

toString() → {string}

show information of object

Returns:
Type
string

copy() → {Stack}

return a copy of this object.

Returns:
Type
Stack