Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

algorithms_and_data_structures

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algorithms_and_data_structures - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

__tests__/bubble_sort.test.js

13

index.js

@@ -0,5 +1,12 @@

'use strict';
const LinkedList = require('./src/linked_list.js');
const Duplicate = require('./src/linked_list.js');
//data structures
const createLinkedList = require('./src/linked_list.js');
module.exports = { LinkedList, Duplicate }
//algorithms
const bubbleSort = require('./src/bubble_sort.js');
module.exports = {
createLinkedList,
bubbleSort
};
{
"name": "algorithms_and_data_structures",
"version": "0.0.4",
"version": "0.0.5",
"description": "Algorithms and data structures in javascript.",
"repository": {
"type" : "git",
"url" : "https://github.com/Introvertuous/algorithms_and_data_structures"
},
"scripts": {

@@ -9,2 +13,3 @@ "test": "jest"

"devDependencies": {
"eslint": "^3.7.1",
"jest-cli": "^15.1.1"

@@ -11,0 +16,0 @@ },

# Algorithms and Data Structures
This project is an attempt to implement a collection of algorithms and data structures in pure javascript.
# Data Structures
- ~~Linked List~~
## Data Structures
- ~~[Linked List](https://en.wikipedia.org/wiki/Linked_list)~~
# Algorithms
- Dijkstra
## Algorithms
- [Dijkstra](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)

@@ -0,6 +1,5 @@

'use strict';
'use strict'
let Node = {
init(data, next) {
init(data=null, next=null) {
this.data = data;

@@ -11,6 +10,8 @@ this.next = next;

};
function createNode() {
return Object.create(Node).init(...arguments);
}
module.exports = {
let LinkedList = {
init() {
this._length = 0;
this._head = null;

@@ -22,16 +23,18 @@ this._tail = null;

pushFirst(data) {
let n = Object.create(Node).init(data, this._head);
let n = createNode(data, this._head);
this._head = n;
if(this._length == 0)
if(this._tail === null)
this._tail = n;
this._length++;
},
popFirst() {
if(this._length == 0)
if(this._head === null)
return null;
let d = this._head.data;
this._head = this._head.next;
if(--this._length == 0)
if(this._head === this._tail) {
this._head = null;
this._tail = null;
}
else
this._head = this._head.next;
return d;

@@ -41,4 +44,4 @@ },

pushLast(data) {
let n = Object.create(Node).init(data, null);
if(this._length == 0)
let n = createNode(data, null);
if(this._head === null)
this._head = n;

@@ -48,7 +51,6 @@ else

this._tail = n;
this._length++;
},
reverse() {
if(this._length == 0)
if(this._head === null)
return;

@@ -63,3 +65,3 @@ this._tail = this._head;

if(next === null)
break
break;
this._head = next;

@@ -70,2 +72,24 @@ next = next.next;

get(i) {
let curr = this._head;
while(curr != null && i > 0) {
curr = curr.next;
i--;
}
return curr;
},
middle() {
let curr = this._head;
let halfCurr = this._head;
let count = 1;
while(curr != null) {
if(count % 2 == 0)
halfCurr = halfCurr.next;
curr = curr.next;
count++;
}
return halfCurr.data;
},
[Symbol.iterator]() {

@@ -79,6 +103,11 @@ let curr = undefined;

done: (curr == undefined)
}
};
}
}
};
}
};
function createLinkedList() {
return Object.create(LinkedList).init();
}
module.exports = createLinkedList;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc