Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 518 Bytes

recursividad.md

File metadata and controls

27 lines (21 loc) · 518 Bytes

Breves conceptos de recursividad

Listas

public static <T> int count(Node<T> first){
    if(first == null) return 0;
    return 1 + count(first.getNext());
}

Árboles

public static <T> int count(TreeNode<T> root){
    if(root == null) return 0;
    int childrenNodeCount = 1;
    for(TreeNode<T> child: root.getChildren()){
        childrenNodeCount += count(child);
    }
    return childrenNodeCount;
}