insert: Insert a key-value pair into a bst

Description Usage Arguments Examples

Description

If the given key is already present in the tree, the associated value will be overwritten, with a warning.

Usage

1
2
3
4
insert(tree, key, value, ...)

## S3 replacement method for class 'bst'
tree[key] <- value

Arguments

tree

A bst

key

The key to insert

value

The value to insert

...

Other arguments (not used)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
mytree <- bst()
mytree <- insert(mytree, "a", 7)

# there is no type-checking, so you can do, eg:
mytree <- insert(mytree, 3.14, 9)

# insert has no  side-effects
mytree2 <- insert(mytree, "k", 10)
retrieve(mytree, "k") # NULL
retrieve(mytree2, "k") # 10
# or use [
mytree["q"] <- 15

tarakc02/rbst documentation built on May 31, 2019, 3:55 a.m.