namastey-stack
v1.0.1
Published
A package for implementing the Stack data structure with various important methods.
Downloads
7
Maintainers
Readme
namastey-stack
Brief Description:
namastey-stack
is a JavaScript package that implements the Stack data structure with various important methods for managing a collection of elements in a Last In, First Out (LIFO) order.
Features
- push(element): Adds an element to the top of the stack.
- pop(): Removes and returns the element at the top of the stack. Returns
null
if the stack is empty. - peek(): Returns the top element of the stack without removing it. Returns
null
if the stack is empty. - isEmpty(): Checks if the stack is empty. Returns
true
if empty, otherwisefalse
. - size(): Returns the number of elements in the stack.
- clear(): Removes all elements from the stack.
Installation
To install the package globally, use the following command:
npm install -g .
Examples
const Stack = require('namastey-stack');
// or
// import Stack from "namastey-stack"
const stack = new Stack();
stack.push(10);
stack.push(20);
console.log(stack.peek()); // Output: 20
console.log(stack.pop()); // Output: 20
console.log(stack.size()); // Output: 1
stack.clear();
console.log(stack.isEmpty()); // Output: true