Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kl.giz1.tree;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Set;
- public class Tree {
- private Node root;
- public Tree(Node root) {
- this.root = root;
- }
- public int getHeight() {
- return getHeight(root, 0);
- }
- private static int getHeight(Node parent, int level) {
- Integer maxChildrenLabel = parent.getChildren().stream()
- .map(child -> getHeight(child, level + 1))
- .max(Integer::compareTo).orElse(0);
- return Math.max(parent.getLabel(), maxChildrenLabel);
- }
- public int getMaxLabel() {
- return getMaxLabel(root);
- }
- private static int getMaxLabel(Node parent) {
- Integer childrenMaxLabel = parent.getChildren().stream()
- .map(Tree::getMaxLabel)
- .max(Integer::compareTo).orElse(parent.getLabel());
- return Math.max(parent.getLabel(), childrenMaxLabel);
- }
- public Node getNodeWithHighestChildrenAmount() {
- return getNodeWithHighestChildrenAmount(root);
- }
- private static Node getNodeWithHighestChildrenAmount(Node parent) {
- Node childWithHighestChildrenAmount = parent.getChildren().stream()
- .max(Comparator.comparingInt(child -> getNodeWithHighestChildrenAmount(child).getChildrenAmount()))
- .orElse(parent);
- return parent.getChildrenAmount() > childWithHighestChildrenAmount.getChildrenAmount() ? parent : childWithHighestChildrenAmount;
- }
- public Set<Node> getCutVerticesNodes() {
- }
- public Set<List<Node>> getBlocks() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement