Sha256: 211ef816910167870cd50e2a52338b4f1fa0c6436563264db6e628b10c10164a

Contents?: true

Size: 553 Bytes

Versions: 396

Compression:

Stored size: 553 Bytes

Contents

module.exports = class BinarySearchTree

  constructor: (@data) ->
    @left  = undefined
    @right = undefined

  insert: (value) ->
    if value <= @data
      @insertLeft value
    else
      @insertRight value

  insertLeft: (value) ->
    if not @left
      @left = new BinarySearchTree value
    else
      @left.insert value

  insertRight: (value) ->
    if not @right
      @right = new BinarySearchTree value
    else
      @right.insert value

  each: (fn) ->
    @left.each(fn)  if @left
    fn.call @, @data
    @right.each(fn) if @right

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.6.20 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.19 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.18 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.17 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.16 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.15 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.14 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.13 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.12 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.11 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.10 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.9 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.8 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.7 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.6 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.5 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.4 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.3 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.2 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.6.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee