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.2.1.119 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.118 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.117 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.116 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.115 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.114 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.113 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.111 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.110 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.109 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.108 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.107 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.106 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.105 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.104 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.103 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.102 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.101 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.100 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.99 tracks/coffeescript/exercises/binary-search-tree/example.coffee