Home Article Practice 算法1

算法1

2021-10-26 17:38  views:563  source:青辞    

//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');
// }



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

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