Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package com.kl.giz1.tree;
  2.  
  3. import java.util.Comparator;
  4. import java.util.List;
  5. import java.util.Set;
  6.  
  7. public class Tree {
  8.  
  9. private Node root;
  10.  
  11. public Tree(Node root) {
  12. this.root = root;
  13. }
  14.  
  15. public int getHeight() {
  16. return getHeight(root, 0);
  17. }
  18.  
  19. private static int getHeight(Node parent, int level) {
  20. Integer maxChildrenLabel = parent.getChildren().stream()
  21. .map(child -> getHeight(child, level + 1))
  22. .max(Integer::compareTo).orElse(0);
  23. return Math.max(parent.getLabel(), maxChildrenLabel);
  24. }
  25.  
  26. public int getMaxLabel() {
  27. return getMaxLabel(root);
  28. }
  29.  
  30. private static int getMaxLabel(Node parent) {
  31. Integer childrenMaxLabel = parent.getChildren().stream()
  32. .map(Tree::getMaxLabel)
  33. .max(Integer::compareTo).orElse(parent.getLabel());
  34. return Math.max(parent.getLabel(), childrenMaxLabel);
  35. }
  36.  
  37. public Node getNodeWithHighestChildrenAmount() {
  38. return getNodeWithHighestChildrenAmount(root);
  39. }
  40.  
  41. private static Node getNodeWithHighestChildrenAmount(Node parent) {
  42. Node childWithHighestChildrenAmount = parent.getChildren().stream()
  43. .max(Comparator.comparingInt(child -> getNodeWithHighestChildrenAmount(child).getChildrenAmount()))
  44. .orElse(parent);
  45. return parent.getChildrenAmount() > childWithHighestChildrenAmount.getChildrenAmount() ? parent : childWithHighestChildrenAmount;
  46. }
  47.  
  48. public Set<Node> getCutVerticesNodes() {
  49.  
  50. }
  51.  
  52. public Set<List<Node>> getBlocks() {
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement