Created
December 2, 2016 01:58
-
-
Save jooyunghan/6f2ca1ccf7a70e99d7662aaf1e353dd2 to your computer and use it in GitHub Desktop.
Binary inorder traversal using generator (and its babel-transpiled)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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