Skip to content

Instantly share code, notes, and snippets.

View Zekfad's full-sized avatar
🤡
depading updendencies / clown (🤡)

Yaroslav Vorobev Zekfad

🤡
depading updendencies / clown (🤡)
View GitHub Profile
@bellbind
bellbind / dijkstra.js
Created July 11, 2012 07:27
[javascript]dijkstra algorithm (with custom data structure)
// Dijkstra Algorithm Example
// - Using suite data structure make algorithm clearer
// compile graph data to vertices structure: {"label": Vertex, ...}
// - Graph: [{from: "label", to: "label". cost: number}, ...]
// - Vertex: {label: string, edges: [{dest: Vertex, cost: number}, ...]}
var compileVertices = function (graph) {
var vs = {};
graph.forEach(function (edge) {
if (!vs[edge.from]) vs[edge.from] = {label: edge.from, edges: []};