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.0.5 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.0.4 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.0.3 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.0.2 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.0.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.0.0.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.4.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.4.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.3.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.2.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.2.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.1.2 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.1.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.1.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.0.1 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-1.0.0 tracks/coffeescript/exercises/binary-search-tree/example.coffee