This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tp04.ejercicio1; | |
import static org.junit.Assert.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class ArbolBinarioTest { | |
private ArbolBinario<Integer> arbolBinarioTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parcial { | |
public ListaGenerica<Vertice<T>> maxBottleneckPath(Grafo<T> g) { | |
ListaGenerica<ListaGenerica<Vertice<T>>> caminos = new ListaGenerica<ListaGenerica<Vertice<T>>>(); | |
boolean[] visitados; | |
agregarCaminos(g, indice_s, indice_t, visitados, caminos); | |
return selectMaxBottleneckPath(caminos) | |
} | |
public selectMaxBottleneckPath(paths) { //comparar los pesos de las aristas con menor peso de cada camino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALUE = 'global' | |
module A | |
VALUE = 'A' | |
class B | |
VALUE = 'B' | |
def self.value | |
VALUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: Cómo hago que funcione con métodos que reciben parámetros? | |
# Referencia: http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/ | |
module Countable | |
module ClassMethods | |
def count_invocations_of(sym) | |
alias_method "original_#{sym}".to_sym, sym | |
define_method(sym) do | |
start_counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
executions = 100_000_000 | |
Benchmark.bm do |conditional_assignment| | |
conditional_assignment.report { executions.times do a ||= 1; end } | |
conditional_assignment.report { executions.times do a = a || 1; end } | |
end | |
=begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pie | |
def make | |
add_main_ingredient | |
add_secondary_ingredients | |
cook | |
add_toppings | |
let_cool | |
end | |
def add_ingredient(ingredient) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declara 2 arreglos de 0 a n-1 de booleans inicializados como false en todas sus posiciones. | |
boolean permissions[0:n-1] = ([n] false) | |
boolean requesters[0:n-1] = ([n] false) | |
process Coordinator { | |
while true { | |
int i = 0 | |
while !requesters[i] { // Barre repetidamente el arreglo buscando un proceso que esté pidiendo entrar a su sección crítica. | |
i = (i + 1) MOD n | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sem free_detectors = 3 // Cantidad de detectores libres a cada instante | |
sem allocation = 1 // Limita la cantidad de personas que buscan ascensor al mismo tiempo | |
// Declara un arreglo de 0 a n-1 de booleans inicializados como false en todas sus posiciones. | |
// Representa los detectores valiendo para cada uno true si está ocupado o false si está libre. | |
boolean detector_taken[0:n-1] = ([n] false) | |
process Person[w = 1 to 100] { | |
p(free_detectors) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queue resource_queue[5] = [r1, r2, r3, r4, r5] | |
sem resources = 5 | |
sem queue_mutex = 1 | |
process Consumer { | |
p(resources) | |
p(queue_mutex) | |
resource my_resource = pop(resource_queue) | |
v(queue_mutex) | |
OlderNewer