Created
October 3, 2019 16:16
-
-
Save jmlon/3d97b2802075851c2be578b254b6a32b to your computer and use it in GitHub Desktop.
Ejemplo de ordenamiento jerarquico a partir de dos campos de un ADT
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 edu.upb.estalg.ordenacion.quiz4; | |
import edu.princeton.cs.algs4.Quick; | |
import edu.princeton.cs.algs4.StdOut; | |
import org.jetbrains.annotations.Contract; | |
public class Pelicula_2019 implements Comparable<Pelicula_2019> { | |
private String nombre; | |
private int calificacion; | |
private long recaudo; | |
public Pelicula_2019(String n, int c, long r) { | |
nombre=n; | |
calificacion=c; | |
recaudo=r; | |
} | |
@Override | |
public int compareTo(Pelicula_2019 b) { | |
if (calificacion<b.calificacion) return 1; | |
if (calificacion>b.calificacion) return -1; | |
if (recaudo<b.recaudo) return 1; | |
if (recaudo>b.recaudo) return -1; | |
return 0; | |
} | |
public static void ordernarPeliculas(Pelicula_2019[] lasPeliculas) { | |
Quick.sort(lasPeliculas); | |
} | |
public static void main(String[] args) { | |
Pelicula_2019[] peliculas = { | |
new Pelicula_2019("Silence of the lambs", 3, 1000000), | |
new Pelicula_2019("Spiderman", 3, 1500000), | |
new Pelicula_2019("El renacido", 2, 500000), | |
new Pelicula_2019("Night at the museum", 4, 1600000), | |
new Pelicula_2019("A new hope", 5, 2000000), | |
new Pelicula_2019("Eclipse", 2, 2000000), | |
}; | |
ordernarPeliculas(peliculas); | |
for(Pelicula_2019 p: peliculas) | |
StdOut.println( String.format("%1$20s",p.nombre)+"\t"+p.calificacion+"\t"+String.format("%1$10d",p.recaudo)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment