Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set_next(root, new_node) {
- if(root) {
- let current = root;
- while(current.next) {
- current = current.next;
- }
- current.next = new_node;
- return root;
- }
- else {
- return new_node;
- }
- }
- set_child_next(root, new_node) {
- if(root) {
- if(root.child) {
- return set_next(root, new_node);
- }
- else {
- root.child = new_node;
- return root;
- }
- }
- else {
- return new_node;
- }
- }
- let root = null;
- root = set_next(root, new Node(...));
- // or in case of we wanting to set: node.child, node.child.next, node.child.next.next, etc...
- root = set_child_next(root, new Node(...));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement