Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created December 2, 2016 01:58
Show Gist options
  • Save jooyunghan/6f2ca1ccf7a70e99d7662aaf1e353dd2 to your computer and use it in GitHub Desktop.
Save jooyunghan/6f2ca1ccf7a70e99d7662aaf1e353dd2 to your computer and use it in GitHub Desktop.
Binary inorder traversal using generator (and its babel-transpiled)
var _marked = [inorder].map(regeneratorRuntime.mark);
function inorder(t) {
return regeneratorRuntime.wrap(function inorder$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (t) {
_context2.next = 2;
break;
}
return _context2.abrupt("return");
case 2:
return _context2.delegateYield(inorder(t.left), "t0", 3);
case 3:
_context2.next = 5;
return t;
case 5:
return _context2.delegateYield(inorder(t.right), "t1", 6);
case 6:
case "end":
return _context2.stop();
}
}
}, _marked[1], this);
}
function* inorder(t) {
if(!t) return
yield* inorder(t.left)
yield t
yield* inorder(t.right)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment