首页 文章 算法1

算法1

2021-10-26 17:38  浏览数:580  来源:青辞    

//define tracer variables {
const treeTracer = new GraphTracer('Traversal In-order');
const arrayTracer = new Array1DTracer('Print In-order');
const logger = new LogTracer('Log');
Layout.setRoot(new VerticalLayout([treeTracer, arrayTracer, logger]));
treeTracer.set(G);
treeTracer.layoutTree(5);
arrayTracer.set(new Array(T.length).fill('-'));
Tracer.delay();
// }
let index = 0;
function inOrder(root, parent) {
if (root === -1) {
// logger {
logger.println('No more nodes. Backtracking.');
Tracer.delay();
// }
return;
}
// visualize {
logger.println(`Reached ${root}`);
treeTracer.visit(root, parent);
Tracer.delay();
logger.println(` Going left from ${root}`);
Tracer.delay();
// }
inOrder(T[root][0], root);
// visualize {
logger.println(`Printing ${root}`);
treeTracer.leave(root);
arrayTracer.patch(index++, root);
Tracer.delay();
logger.println(` Going right from ${root}`);
Tracer.delay();
// }
inOrder(T[root][1], root);
}
inOrder(5); // node with key 5 is the root
// logger {
logger.println('Finished');
// }



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)