Merge pull request #3 from LinlyBoi/Sort-Topologique
Recursive Topological sort implemented (Presumably).
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class RecipeTree
|
public class RecipeTree
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -62,4 +64,19 @@ public class RecipeTree
|
|||||||
root.printNode();
|
root.printNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stack<RecipeNode> sortTopologically(RecipeNode currentNode) {
|
||||||
|
Stack<RecipeNode> recipeStack = new Stack<>();
|
||||||
|
|
||||||
|
if(currentNode.getChildren() == null) {
|
||||||
|
recipeStack.push(currentNode);
|
||||||
|
return recipeStack;
|
||||||
|
} else {
|
||||||
|
for (RecipeNode childNode : currentNode.children) {
|
||||||
|
recipeStack.push(currentNode);
|
||||||
|
sortTopologically(childNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recipeStack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user