Skip to content

Instantly share code, notes, and snippets.

@IgnacioPardo
Created September 3, 2021 18:51
Show Gist options
  • Save IgnacioPardo/f945e593907b6616648d7a5fcc96f0be to your computer and use it in GitHub Desktop.
Save IgnacioPardo/f945e593907b6616648d7a5fcc96f0be to your computer and use it in GitHub Desktop.
import java.util.Arrays;
class Main {
public static void main(String[] args) {
MedicalShifts t_harry = new MedicalShifts("harry", 0);
MedicalShifts t_hermione = new MedicalShifts("hermione", 3);
MedicalShifts t_ron = new MedicalShifts("ron", 1);
MedicalShifts t_luna = new MedicalShifts("luna", 5);
MedicalShifts t_voldemort = new MedicalShifts("voldemort", 8);
MedicalShifts[] turnos_hogwarts = {t_harry, t_hermione, t_ron, t_luna, t_voldemort};
for (MedicalShifts turno : turnos_hogwarts) {
System.out.println(turno);
}
System.out.println("_____________________");
Arrays.sort(turnos_hogwarts);
for (MedicalShifts turno : turnos_hogwarts) {
System.out.println(turno);
}
System.out.println("_____________________");
//MedicalShift peek()
//return turnos_hogwarts[0]
System.out.println(turnos_hogwarts[0]);
System.out.println("_____________________");
for (MedicalShifts turno : turnos_hogwarts) {
System.out.println(turno);
}
System.out.println("_____________________");
//MedicalShift pop()
MedicalShifts to_pop = turnos_hogwarts[0];
MedicalShifts[] turnos_hogwarts_popeado = new MedicalShifts[turnos_hogwarts.length - 1];
for (int i = 1; i<turnos_hogwarts.length; i++){
turnos_hogwarts_popeado[i-1] = turnos_hogwarts[i];
}
for (MedicalShifts turno : turnos_hogwarts_popeado) {
System.out.println(turno);
}
System.out.println("Pop: " + to_pop);
System.out.println("_____________________");
//add(t_hagrid)
MedicalShifts t_hagrid = new MedicalShifts("hagrid", 4);
MedicalShifts[] turnos_hogwarts_add = new MedicalShifts[turnos_hogwarts_popeado.length + 1];
for (int i = 0; i < turnos_hogwarts_popeado.length; i++){
turnos_hogwarts_add[i] = turnos_hogwarts_popeado[i];
}
turnos_hogwarts_add[turnos_hogwarts_popeado.length] = t_hagrid;
for (MedicalShifts turno : turnos_hogwarts_add) {
System.out.println(turno);
}
System.out.println("_____________________");
Arrays.sort(turnos_hogwarts_add);
for (MedicalShifts turno : turnos_hogwarts_add) {
System.out.println(turno);
}
}
}
public class MedicalShifts implements Comparable<MedicalShifts> {
String name;
int id;
public MedicalShifts(String n, int i){
this.name = n;
this.id = i;
}
public String toString(){
return this.name;
}
@Override
public int compareTo(MedicalShifts otro){
if (this.id < otro.id){
return -1;
}
else if(this.id > otro.id){
return 1;
}
else{
return 0;
}
}
}
public class Queue<T>{
T[] q = (T[]) new Comparable[0];
public Boolean isEmpty(){
if (q.length == 0){
return true;
}
else {
return false;
}
}
public T peek(){
return q[0];
}
public T pop(){
T to_pop = q[0];
T[] q_popeada = (T[]) new Comparable[this.q.length - 1];
for (int i = 1; i < this.q.length; i++){
q_popeada[i-1] = this.q[i];
}
this.q = q_popeada;
return to_pop;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment