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.180 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.179 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.178 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.177 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.176 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.175 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.174 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.173 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.172 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.171 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.170 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.169 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.167 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.166 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.165 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.164 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.163 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.162 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.161 tracks/coffeescript/exercises/binary-search-tree/example.coffee
trackler-2.2.1.160 tracks/coffeescript/exercises/binary-search-tree/example.coffee