Skip to content

Instantly share code, notes, and snippets.

@mgiagante
Last active June 24, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgiagante/1fa8fee72ca35311ddd593104d39d4ef to your computer and use it in GitHub Desktop.
Save mgiagante/1fa8fee72ca35311ddd593104d39d4ef to your computer and use it in GitHub Desktop.
add(punto)
if (mi nivel es par)
if (el x del punto a agregar es < que mi propio x)
this.hijoIzquierdo() == null ? this.agregarHijoIzquierdo(punto) : this.hijoIzquierdo().add(punto)
else
this.hijoDerecho() == null ? this.agregarHijoDerecho(punto) : this.hijoIzquierdo().add(punto)
if (mi nivel es impar)
if (el y del punto a agregar es < que mi propio y)
this.hijoIzquierdo() == null ? this.agregarHijoIzquierdo(punto) : this.hijoIzquierdo().add(punto)
else
this.hijoDerecho() == null ? this.agregarHijoDerecho(punto) : this.hijoIzquierdo().add(punto)
minX()
if (mi nivel es par)
return (tiene hijo izquierdo) ? this.hijoIzquierdo().minX() : this.x()
else
minPorIzquierda = (tiene hijo izquierdo) ? this.hijoIzquierdo().minX() : this.x();
minPorDerecha = (tiene hijo derecho) ? this.hijoDerecho().minX() : this.x()
return Math.min(minPorIzquierda, minPorDerecha)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment