"use strict"; //var tab = window.open(); topoSort(); //tab.close(); function topoSort() { var topo = []; // when done this list will have the nodes in topo sort order var G = graph_fig_9_4(); //var G = graph_ex2(); //var G = graph_cycle(); // cycle in this one var origG = G.print(false); //G.print(); return; var queue = []; // contains nodes with in degree 0 for(var i=0; i 0 ) { fn = queue.shift(); topo.push(fn); elst = G.nodes[fn].adj; while (elst !== null) { // collect out arc to nodes tns.push(elst.tn); elst = elst.next; } while (tns.length>0) { tn = tns.pop(); G.delEdge(fn,tn); if (G.nodes[tn].indeg===0) { queue.push(tn); } } } if (topo.length !== G.nnum) { alert("cycle found"); return false; } // print the topo order var str = ""; for (var k=0; k'); lst = this.nodes[i].adj; while (lst!==null) { tab.document.write("       -----> "+lst.tn + "
"); lst = lst.next; } } }, print: function(flag) { var lst; var str = ""; for (var i=0; i