Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in depth first search: Incorrect order #24

Open
FrankDupree opened this issue Apr 5, 2018 · 0 comments
Open

Error in depth first search: Incorrect order #24

FrankDupree opened this issue Apr 5, 2018 · 0 comments

Comments

@FrankDupree
Copy link

Tree.js traverseDepthFirst doesn't return the correct order.

Tree.prototype.traverseDepthFirst= function(fn){
	this.children.forEach(function(child){
		child.traverseDepthFirst(fn);
	});

	fn(this)
}

Based on the example dataset:

var tree = new Tree(1);
var branch1 = tree.addChild(2);
var branch2 = tree.addChild(3);
var branch3 = tree.addChild(4);
branch1.addChild(5);
branch1.addChild(6);
branch3.addChild(7).addChild(8);

The correct order should be: [1, 2, 5, 6, 3, 4, 7, 8]
Instead it returns: [5, 6, 2, 3, 8, 7, 4, 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant