Skip to content

Instantly share code, notes, and snippets.

@PunkSage
PunkSage / Topological sorting
Last active June 17, 2016 09:42
Topological sorting
var Graph = function() {
var nodes = {
'a': { id: 'a', state: 'unvisited', output: ['b','c','d']},
'b': { id: 'b', state: 'unvisited', output: ['e']},
'c': { id: 'c', state: 'unvisited', output: ['e']},
'd': { id: 'd', state: 'unvisited', output: ['f']},
'e': { id: 'e', state: 'unvisited', output: ['f']},
'f': { id: 'f', state: 'unvisited', output: ['g']},
'g': { id: 'g', state: 'unvisited', output: []}
/* Verify if a given string has a proper parenthesis setup */
function verify(str) {
var array = str.split('');
var stack = [];
var left = ['{','[','('];
var right = ['}',']',')'];
var opposite = {
')':'(',
'}':'{',