Created
September 5, 2016 00:23
-
-
Save alvareztech/e6af1be7b3d67a9848d2ceb9fc5cff1f to your computer and use it in GitHub Desktop.
Ejemplo colas de prioridad en Java. PriorityQueue.
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 tech.alvarez; | |
import java.util.PriorityQueue; | |
import java.util.Queue; | |
public class Main { | |
public static void main(String[] args) { | |
Queue<Persona> cola = new PriorityQueue<Persona>(); | |
cola.add(new Persona("Daniel", 1)); | |
cola.add(new Persona("Katherine", 3)); | |
cola.add(new Persona("Julio", 2)); | |
cola.add(new Persona("Maria", 1)); | |
while (!cola.isEmpty()) { | |
Persona a = cola.remove(); | |
System.out.println(a.getNombre() + " " + a.getTipo()); | |
} | |
} | |
} |
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 tech.alvarez; | |
public class Persona implements Comparable<Persona> { | |
private String nombre; | |
private int tipo; // 1 normal, 2 tercera edad, 3 embarazada | |
public Persona(String nombre, int tipo) { | |
this.nombre = nombre; | |
this.tipo = tipo; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public int getTipo() { | |
return tipo; | |
} | |
public void setTipo(int tipo) { | |
this.tipo = tipo; | |
} | |
@Override | |
public int compareTo(Persona o) { | |
if (tipo < o.getTipo()) { | |
return 1; | |
} else if (tipo > o.getTipo()) { | |
return -1; | |
} else { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public class Pila {
Nodo inicio;
Nodo fin;
}