/DataTypes

Extend JS by additional data types Stack, Queue

Primary LanguageJavaScriptMIT LicenseMIT

Build Status

DataTypes

Extend JS by additional data types:

Getting started

If you need all these data types:

var DataTypes = require('datatypes');

Or you can include only certain data type:

var Stack = require('stack');
Run tests
mocha test
Make bundle using browserify
browserify src/datatypes.js -o dist/bundle.js

Stack

var stack = new DataTypes.Stack();

stack.push('hello');
stack.push('world');
stack.size(); // 2

var world = stack.pop(); // 'world'
stack.size(); // 1

var hello = stack.pop(); // 'hello'
stack.size(); // 0
Methods
push(element) // Adds element at the top of stack.
pop() // Decrements size of stack and returns the element that was previously the top one.
peek() // Gets the head element of stack.
size() // Returns the size of stack.

Queue

var queue = new DataTypes.Queue();

queue.enqueue('hello');
queue.enqueue('world');
queue.size(); // 2

var hello = queue.dequeue(); // 'hello'
queue.size(); // 1

var world = queue.dequeue(); // 'world'
queue.size(); // 0
Methods
enqueue(element) // Adds element at the end of queue.
dequeue() // Decrements size of queue and returns the element that was at the start of queue.
size() // Returns the size of queue.