Skip to main content
exclusive branches
Source Link
dfhwze
  • 14.2k
  • 3
  • 40
  • 101

Review

Well written API, but I am not happy with this one:

traverse({ preorder, postorder, levelorder })

preorder and postorder can be combined, but they are always mutually exclusive with levelorder.

traverse({ preorder, postorder, levelorder }) {
  if (levelorder) {
      // levelorder ..
  }
  else {
      // preorder conditional and/or postorder conditional ..
  }
  return this;
}

Instead, use 2 separate methods, each doing their own well known type of traversal.

DFS

 traverseDepthFirst({ preorder, postorder })

BFS

 traverseBreadthFirst({ levelorder })

Some general thoughts:

  • should you allow cyclic graphs?
  • should you want to traverse up the ancestors?

Review

Well written API, but I am not happy with this one:

traverse({ preorder, postorder, levelorder })

preorder and postorder can be combined, but they are always mutually exclusive with levelorder.

Instead, use 2 separate methods, each doing their own well known type of traversal.

DFS

 traverseDepthFirst({ preorder, postorder })

BFS

 traverseBreadthFirst({ levelorder })

Some general thoughts:

  • should you allow cyclic graphs?
  • should you want to traverse up the ancestors?

Review

Well written API, but I am not happy with this one:

traverse({ preorder, postorder, levelorder })

preorder and postorder can be combined, but they are always mutually exclusive with levelorder.

traverse({ preorder, postorder, levelorder }) {
  if (levelorder) {
      // levelorder ..
  }
  else {
      // preorder conditional and/or postorder conditional ..
  }
  return this;
}

Instead, use 2 separate methods, each doing their own well known type of traversal.

DFS

 traverseDepthFirst({ preorder, postorder })

BFS

 traverseBreadthFirst({ levelorder })

Some general thoughts:

  • should you allow cyclic graphs?
  • should you want to traverse up the ancestors?
Source Link
dfhwze
  • 14.2k
  • 3
  • 40
  • 101

Review

Well written API, but I am not happy with this one:

traverse({ preorder, postorder, levelorder })

preorder and postorder can be combined, but they are always mutually exclusive with levelorder.

Instead, use 2 separate methods, each doing their own well known type of traversal.

DFS

 traverseDepthFirst({ preorder, postorder })

BFS

 traverseBreadthFirst({ levelorder })

Some general thoughts:

  • should you allow cyclic graphs?
  • should you want to traverse up the ancestors?