R/size.R

#' Get the size of a tree
#' 
#' Returns the number of nodes in a binary search tree
#' 
#' @param tree A \code{bst}
#' @export
size <- function(tree) UseMethod("size")

#' @export
size.bst <- function(tree) size(tree$root)

size.bstnode <- function(node) {
    node$n
}
size.NULL <- function(nada) 0L

#' Is the tree empty?
#' 
#' @param tree A \code{bst}
#' 
#' @export
is_empty <- function(tree) {
    size(tree) == 0L
}
tarakc02/rbst documentation built on May 31, 2019, 3:55 a.m.