"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Node=exports.DirectedGraph=void 0;exports.DirectedGraph=class{constructor(){this.root=null,this.curNode=null}add(e){const r=new t(e,null);null===this.root?(this.root=r,this.curNode=this.root):(r.setParentNode(this.curNode),this.curNode.setNextNode(r),this.curNode=r)}preAdd(t){return this.add(t),!this.checkCycle()&&(this.rollBack(),!0)}rollBack(){if(null===this.curNode)return;const t=this.curNode.getParentNode();null!==t&&(t.setNextNode(null),this.curNode=t)}checkCycle(){if(null===this.root)return!1;const t={};t[this.root.getData()]=!0;let e=this.root;for(;e&&e.hasNext();){if(e=e.getNextNode(),t[e.getData()])return!0;t[e.getData()]=!0}return!1}getRoot(){return this.root}getCurNode(){return this.curNode}};class t{constructor(t,e){this.parentNode=null,this.data=t,this.nextNode=e}hasNext(){return null!==this.nextNode}getData(){return this.data}getParentNode(){return this.parentNode}setParentNode(t){this.parentNode=t}getNextNode(){return this.nextNode}setNextNode(t){this.nextNode=t}}exports.Node=t;